Repository navigation
fix(rails): do not report the cause of an already captured view error twice - #3167
pcbeingused33 wants to merge 5 commits into
Conversation
…captured Hub#capture_exception only skipped the exact exception object it had marked. With register_error_subscriber, the middleware captures an ActionView::Template::Error and the error subscriber later reports its cause, which is a different object, so a view error became two events. An event already carries the whole cause chain, so mark every exception in the chain when capturing and skip any exception whose chain contains a marked one. Fixes getsentry#3166 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
| !!exc.instance_variable_get(CAPTURED_SIGNATURE) | ||
| # An event already carries the whole cause chain, so capturing any part of a | ||
| # chain that was captured would duplicate it. | ||
| Utils::ExceptionCauseChain.exception_to_array(exc).any? do |e| |
There was a problem hiding this comment.
this changes the capture semantics substantially, I'd rather prefer we fix this for the rails specific issue.
…already captured" This reverts commit 20dad7e.
Narrow the fix to sentry-rails as requested in review: the previous commit is reverted, so Sentry.exception_captured? and Hub#capture_exception keep their original semantics. Rails::CaptureExceptions now marks the causes of the exception it captured, so ErrorSubscriber does not report them again, and it skips an exception whose cause the error reporter already reported (development order). Fixes getsentry#3166 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks, agreed. I reverted the core change ( This comment was drafted with Claude Code. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a240ac1. Configure here.
CaptureExceptions marked the causes of the exception it handled even when capture_exception returned no event (e.g. an excluded wrapper), so a later ErrorSubscriber report of a non-excluded cause was dropped as a duplicate. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Good catch, Bugbot was right: This comment was drafted with Claude Code. |
|
Hi @sl0thentr0py, friendly ping: the review feedback should be addressed now. Happy to adjust anything else. Thanks! |
|
Hi, I believe the review feedback is addressed now. Could you take another look when you have a moment? Happy to adjust anything else. Thanks! |
|
Sorry @pcbeingused33 I was on vacation. What we should do for now is actually not report unhandled exceptions at all from In the future, we will consider removing the |
Unhandled exceptions are already captured by the CaptureExceptions middleware, which reports the outermost exception with the request data. With register_error_subscriber enabled, Rails' executor also reports them (for a view error, the cause of ActionView::Template::Error), producing a second, less complete event. ErrorSubscriber now skips reports with handled: false. This replaces the previous CaptureExceptions cause-marking approach, which is reverted. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
No worries, thanks for the review! Done in 30b910f: I reverted the This comment was drafted with Claude Code. |

Fixes #3166
Resolves RUBY-239
Cause
With
register_error_subscriber, an unhandled request exception is captured bySentry::Rails::CaptureExceptionsand also reported toRails.errorbyActionDispatch::Executor. For a view error the executor reports the unwrapped exception (thecauseofActionView::Template::Error), a different object, soErrorSubscribersent a second event without the wrapper's information.Fix
ErrorSubscriber#reportreturns early forhandled: false: unhandled exceptions are left to theCaptureExceptionsmiddleware, which reports the outermost exception with the request data. Handled reports (Rails.error.handle,Rails.error.report(..., handled: true)) are unchanged. The earlier cause-marking change inCaptureExceptionsis reverted.Test
spec/sentry/rails/error_subscriber_spec.rb: ahandled: falsereport is not captured.spec/sentry/rails_spec.rb: withregister_error_subscriber,Rails.error.report(..., handled: false)sends no event, andGET /view_exceptionsends exactly one event, anActionView::Template::Error. All three fail without the change.This pull request was prepared with the assistance of an AI coding agent (Claude Code) and submitted by Alex Castillo, who is responsible for its content.