Skip to content

Commit

Permalink
sentry: Ignore SystemExit and similar exceptions.
Browse files Browse the repository at this point in the history
There are three exceptions in Python3 which are descended from
BaseException, but not Exception: GeneratorExit, KeyboardInterrupt,
and SystemExit.  None of these are suitable to be sent to Sentry.
For example, SystemExit is raised by `sys.exit`; in that sense, it is
never "uncaught" because we chose to cause it explicitly.

Use the suggested form[1] for ignoring specific classes of exceptions.

[1] getsentry/sentry-python#149 (comment)
  • Loading branch information
alexmv authored and timabbott committed Aug 9, 2020
1 parent b5b7bc9 commit 83645a3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion zproject/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
if TYPE_CHECKING:
from sentry_sdk._types import Event, Hint

def add_context(event: 'Event', hint: 'Hint') -> 'Event':
def add_context(event: 'Event', hint: 'Hint') -> Optional['Event']:
if "exc_info" in hint:
_, exc_value, _ = hint["exc_info"]
# Ignore GeneratorExit, KeyboardInterrupt, and SystemExit exceptions
if not isinstance(exc_value, Exception):
return None
from zerver.models import get_user_profile_by_id
with capture_internal_exceptions():
user_info = event.get("user", {})
Expand Down

0 comments on commit 83645a3

Please sign in to comment.