Skip to content

Commit 45bf880

Browse files
authored
Do not crash exceptiongroup (by patching excepthook and keeping the name of the function) (#3099)
By patchinng sys.excepthook and retaining the original name, exceptiongroup is crashing. This is why I changed it to patch exceptgroup and have a new name for the patched function.
1 parent 0983f74 commit 45bf880

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

sentry_sdk/integrations/excepthook.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import sentry_sdk
44
from sentry_sdk.utils import (
55
capture_internal_exceptions,
6-
ensure_integration_enabled,
76
event_from_exception,
87
)
98
from sentry_sdk.integrations import Integration
@@ -47,11 +46,16 @@ def setup_once():
4746

4847
def _make_excepthook(old_excepthook):
4948
# type: (Excepthook) -> Excepthook
50-
@ensure_integration_enabled(ExcepthookIntegration, old_excepthook)
5149
def sentry_sdk_excepthook(type_, value, traceback):
5250
# type: (Type[BaseException], BaseException, Optional[TracebackType]) -> None
5351
integration = sentry_sdk.get_client().get_integration(ExcepthookIntegration)
5452

53+
# Note: If we replace this with ensure_integration_enabled then
54+
# we break the exceptiongroup backport;
55+
# See: https://github.com/getsentry/sentry-python/issues/3097
56+
if integration is None:
57+
return old_excepthook(type_, value, traceback)
58+
5559
if _should_send(integration.always_run):
5660
with capture_internal_exceptions():
5761
event, hint = event_from_exception(

0 commit comments

Comments
 (0)