Skip to content

Commit

Permalink
Do not crash exceptiongroup (by patching excepthook and keeping the n…
Browse files Browse the repository at this point in the history
…ame 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.
  • Loading branch information
antonpirker committed May 23, 2024
1 parent 0983f74 commit 45bf880
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sentry_sdk/integrations/excepthook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sentry_sdk
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
event_from_exception,
)
from sentry_sdk.integrations import Integration
Expand Down Expand Up @@ -47,11 +46,16 @@ def setup_once():

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

# Note: If we replace this with ensure_integration_enabled then
# we break the exceptiongroup backport;
# See: https://github.com/getsentry/sentry-python/issues/3097
if integration is None:
return old_excepthook(type_, value, traceback)

if _should_send(integration.always_run):
with capture_internal_exceptions():
event, hint = event_from_exception(
Expand Down

0 comments on commit 45bf880

Please sign in to comment.