How do you use Sentry?
Sentry Saas (sentry.io)
Version
1.29.2
Steps to Reproduce
Here's a toy example that demonstrates the problem:
try:
try:
raise ExceptionGroup("group", [ValueError("child1"), ValueError("child2")])
finally:
raise TypeError("bar")
except BaseException:
sentry_sdk.capture_exception()
sentry_sdk.capture_exception() receives the TypeError. TypeError.__context__ points to the ExceptionGroup; and then ExceptionGroup.exceptions points to [ValueError("child1"), ValueError("child2")].
Expected Result
The Sentry event should contain all four exceptions: the TypeError, the ExceptionGroup, and the sub-exceptions ValueError("child1") and ValueError("child2").
Additionally, the event should record that the ExceptionGroup is TypeError.__context__ as opposed to TypeError.__cause__.
Note that the sentry_sdk.utils.exceptions_from_error() function actually does this correctly, but it isn't getting invoked in this case. Here's a screenshot of how it looks if I patch the Sentry SDK to always use sentry_sdk.utils.exceptions_from_error():
Actual Result
When the TypeError is passed into sentry_sdk.utils.exceptions_from_error_tuple(), it checks whether the TypeError is an ExceptionGroup or not: https://github.com/getsentry/sentry-python/blob/2.19.2/sentry_sdk/utils.py#L968-L1009 Because the TypeError is not an ExceptionGroup, it calls walk_exception_chain(), which examines TypeError.__context__ to find the ExceptionGroup; but it doesn't recurse into the sub-exceptions ValueError("child1") and ValueError("child2"). So the Sentry event only contains the TypeError and the ExceptionGroup:
Also, the "Related Exceptions" tree in the above screenshot appears to be nonsensical.
I tested this with SDK version 1.29.2, but the bug appears to still be present in the latest version of the code.
How do you use Sentry?
Sentry Saas (sentry.io)
Version
1.29.2
Steps to Reproduce
Here's a toy example that demonstrates the problem:
sentry_sdk.capture_exception()receives theTypeError.TypeError.__context__points to theExceptionGroup; and thenExceptionGroup.exceptionspoints to[ValueError("child1"), ValueError("child2")].Expected Result
The Sentry event should contain all four exceptions: the
TypeError, theExceptionGroup, and the sub-exceptionsValueError("child1")andValueError("child2").Additionally, the event should record that the
ExceptionGroupisTypeError.__context__as opposed toTypeError.__cause__.Note that the
sentry_sdk.utils.exceptions_from_error()function actually does this correctly, but it isn't getting invoked in this case. Here's a screenshot of how it looks if I patch the Sentry SDK to always usesentry_sdk.utils.exceptions_from_error():Actual Result
When the
TypeErroris passed intosentry_sdk.utils.exceptions_from_error_tuple(), it checks whether theTypeErroris anExceptionGroupor not: https://github.com/getsentry/sentry-python/blob/2.19.2/sentry_sdk/utils.py#L968-L1009 Because theTypeErroris not anExceptionGroup, it callswalk_exception_chain(), which examinesTypeError.__context__to find theExceptionGroup; but it doesn't recurse into the sub-exceptionsValueError("child1")andValueError("child2"). So the Sentry event only contains theTypeErrorand theExceptionGroup:Also, the "Related Exceptions" tree in the above screenshot appears to be nonsensical.
I tested this with SDK version 1.29.2, but the bug appears to still be present in the latest version of the code.