Skip to content
  • Jean Boussier's avatar
    8cbc19d8
    Rails standardized error reporting interface · 8cbc19d8
    Jean Boussier authored
    Fix: https://github.com/rails/rails/issues/43472
    
    The reporter is held by the executor, but the `Rails` module provides a
    nicer `Rails.error` shortcut.
    
    For ease of use, two block based specialized methods are exposed.
    
    `handle`, which swallow errors and forward them to the subscribers:
    
    ```ruby
    Rails.error.handle do
      1 + '1' # raises TypeError
    end
    1 + 1 # This will be executed
    ```
    
    `record`, which forward the errors to the subscribes but let it
    continue rewinding the call stack:
    
    ```ruby
    Rails.error.record do
      1 + '1' # raises TypeError
    end
    1 + 1 # This won't be executed.
    ```
    
    For cases where the blocked based API isn't suitable, the lower level
    `report` method can be used:
    
    ```ruby
    Rails.error.report(error, handled: true / false)
    ```
    8cbc19d8
    Rails standardized error reporting interface
    Jean Boussier authored
    Fix: https://github.com/rails/rails/issues/43472
    
    The reporter is held by the executor, but the `Rails` module provides a
    nicer `Rails.error` shortcut.
    
    For ease of use, two block based specialized methods are exposed.
    
    `handle`, which swallow errors and forward them to the subscribers:
    
    ```ruby
    Rails.error.handle do
      1 + '1' # raises TypeError
    end
    1 + 1 # This will be executed
    ```
    
    `record`, which forward the errors to the subscribes but let it
    continue rewinding the call stack:
    
    ```ruby
    Rails.error.record do
      1 + '1' # raises TypeError
    end
    1 + 1 # This won't be executed.
    ```
    
    For cases where the blocked based API isn't suitable, the lower level
    `report` method can be used:
    
    ```ruby
    Rails.error.report(error, handled: true / false)
    ```
Loading