Skip to content

fix(ruby): do not capture an exception whose cause chain was already captured - #3167

Open
pcbeingused333 wants to merge 1 commit into
getsentry:masterfrom
pcbeingused333:fix/capture-exception-cause-chain
Open

pcbeingused333 wants to merge 1 commit into
getsentry:masterfrom
pcbeingused333:fix/capture-exception-cause-chain

Conversation

@pcbeingused333

Copy link
Copy Markdown

Fixes #3166
Resolves RUBY-239

Cause

Hub#capture_exception marks the captured exception object and Sentry.exception_captured? only checks that exact object. With register_error_subscriber, CaptureExceptions captures the ActionView::Template::Error, and ErrorSubscriber later forwards its cause (a different object), so one view error produced two events with different grouping.

Fix

An event already includes the whole cause chain (ExceptionCauseChain), so:

  • Hub#capture_exception marks every exception in the chain after capturing;
  • Sentry.exception_captured? returns true when any exception in the chain is marked.

This follows the suggestion in the issue and covers both orders (wrapper first, or cause first).

Test

Two specs in sentry_spec.rb capture a wrapper and its cause in each order and assert a single event. They fail without the change and pass with it.

AI disclosure

This change was prepared with the assistance of an AI coding agent (Claude).

…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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

With register_error_subscriber, view errors are reported twice: the wrapper by the middleware, and its cause by the error subscriber

1 participant