Skip to content

Commit

Permalink
Add more detail from the rails guide in the section on manually repor…
Browse files Browse the repository at this point in the history
…ting an error
  • Loading branch information
fractaledmind committed Aug 22, 2024
1 parent ef486c5 commit dd827a3
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

Solid Errors is a DB-based, app-internal exception tracker for Rails applications, designed with simplicity and performance in mind. It uses the new [Rails error reporting API](https://guides.rubyonrails.org/error_reporting.html) to store uncaught exceptions in the database, and provides a simple UI for viewing and managing exceptions.

> [!WARNING]
> [!WARNING]
> The current point release of Rails (7.1.3.2) has a bug which severely limits the utility of Solid Errors. Exceptions raised during a web request *are not* reported to Rails' error reporter. There is a fix in the `main` branch, but it has not been released in a new point release. As such, Solid Errors is **not** production-ready unless you are running Rails from the `main` branch or until a new point version is released and you upgrade.
> The original bug report can be found [here](https://github.com/rails/rails/issues/51002) and the pull request making the fix is [here](https://github.com/rails/rails/pull/51050). I will try to backport the fix into the gem directly, but I haven't quite figured it out yet.
Expand Down Expand Up @@ -71,10 +71,50 @@ There are intentionally few features; you can view and resolve errors. That’s

### Manually reporting an Error

Errors can be added to Solid Errors via the Rails error reporting API:
Errors can be added to Solid Errors via the [Rails error reporter](https://guides.rubyonrails.org/error_reporting.html).

There are [three ways](https://guides.rubyonrails.org/error_reporting.html#using-the-error-reporter) you can use the error reporter:

`Rails.error.handle` will report any error raised within the block. It will then swallow the error, and the rest of your code outside the block will continue as normal.

```ruby
result = Rails.error.handle do
1 + '1' # raises TypeError
end
result # => nil
1 + 1 # This will be executed
```

`Rails.error.record` will report errors to all registered subscribers and then re-raise the error, meaning that the rest of your code won't execute.

```ruby
Rails.error.report(error)
Rails.error.record do
1 + '1' # raises TypeError
end
1 + 1 # This won't be executed
```

You can also manually report errors by calling `Rails.error.report`:

```ruby
begin
# code
rescue StandardError => e
Rails.error.report(e)
end
```

All 3 reporting APIs (`#handle`, `#record`, and `#report`) support the following options, which are then passed along to all registered subscribers:

* `handled`: a Boolean to indicate if the error was handled. This is set to `true` by default. `#record` sets this to `false`.
* `severity`: a Symbol describing the severity of the error. Expected values are: `:error`, `:warning`, and `:info`. `#handle` sets this to `:warning`, while `#record` sets it to `:error`.
* `context`: a Hash to provide more context about the error, like request or user details
* `source`: a String about the source of the error. The default source is `"application"`. Errors reported by internal libraries may set other sources; the Redis cache library may use "redis_cache_store.active_support", for instance. Your subscriber can use the source to ignore errors you aren't interested in.

```ruby
Rails.error.handle(context: { user_id: user.id }, severity: :info) do
# ...
end
```

### Configuration
Expand Down

0 comments on commit dd827a3

Please sign in to comment.