Skip to content

Commit 27d7384

Browse files
authored
RescuedExceptionInterceptor: Handle empty configuration (#2428)
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
1 parent e384446 commit 27d7384

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Fix Vernier profiler not stopping when already stopped [#2429](https://github.com/getsentry/sentry-ruby/pull/2429)
1313
- Fix `send_default_pii` handling in rails controller spans [#2443](https://github.com/getsentry/sentry-ruby/pull/2443)
1414
- Fixes [#2438](https://github.com/getsentry/sentry-ruby/issues/2438)
15+
- Fix `RescuedExceptionInterceptor` to handle an empty configuration [#2428](https://github.com/getsentry/sentry-ruby/pull/2428)
1516

1617
## 5.21.0
1718

sentry-rails/lib/sentry/rails/rescued_exception_interceptor.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@ def call(env)
1919
end
2020

2121
def report_rescued_exceptions?
22-
Sentry.configuration.rails.report_rescued_exceptions
22+
# In rare edge cases, `Sentry.configuration` might be `nil` here.
23+
# Hence, we use a safe navigation and fallback to a reasonable default
24+
# of `true` in case the configuration couldn't be loaded.
25+
# See https://github.com/getsentry/sentry-ruby/issues/2386
26+
report_rescued_exceptions = Sentry.configuration&.rails&.report_rescued_exceptions
27+
return report_rescued_exceptions unless report_rescued_exceptions.nil?
28+
29+
# `true` is the default for `report_rescued_exceptions`, as specified in
30+
# `sentry-rails/lib/sentry/rails/configuration.rb`.
31+
true
2332
end
2433
end
2534
end

0 commit comments

Comments
 (0)