Skip to content

Commit

Permalink
RescuedExceptionInterceptor: Handle empty configuration
Browse files Browse the repository at this point in the history
Previously, it could happen that `Sentry.configuration` was `nil`.
In this case, calling `rails` would produce a `NoMethodError`.
We fix this issue by using safe navigation.

Furthermore, this commit ensures we use a reasonable default
in case the configuration couldn't be loaded. Since the config
`report_rescued_exceptions` defaults to `true`, we assume
this value here, too.

Fixes #2386
  • Loading branch information
MrSerth committed Oct 19, 2024
1 parent f3ed31e commit 7cc21d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Bug Fixes

- Fix Vernier profiler not stopping when already stopped [#2429](https://github.com/getsentry/sentry-ruby/pull/2429)
- Fix `RescuedExceptionInterceptor` to handle an empty configuration [#2428](https://github.com/getsentry/sentry-ruby/pull/2428)

## 5.21.0

Expand Down
11 changes: 10 additions & 1 deletion sentry-rails/lib/sentry/rails/rescued_exception_interceptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ def call(env)
end

def report_rescued_exceptions?
Sentry.configuration.rails.report_rescued_exceptions
# In rare edge cases, `Sentry.configuration` might be `nil` here.
# Hence, we use a safe navigation and fallback to a reasonable default
# of `true` in case the configuration couldn't be loaded.
# See https://github.com/getsentry/sentry-ruby/issues/2386
report_rescued_exceptions = Sentry.configuration&.rails&.report_rescued_exceptions
return report_rescued_exceptions unless report_rescued_exceptions.nil?

# `true` is the default for `report_rescued_exceptions`, as specified in
# `sentry-rails/lib/sentry/rails/configuration.rb`.
true
end
end
end
Expand Down

0 comments on commit 7cc21d2

Please sign in to comment.