Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Do not record errors for terminals #924

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Version 6.0.0
* Refactored transports to support multiple URLs. This might affect
you if you have custom subclasses of those. The main change is that
the URL parameter moved from the constructor into the `send` method.
* Do not record from the sys except hook if stdin is a terminal.

Version 5.32.0
--------------
Expand Down
12 changes: 10 additions & 2 deletions raven/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,22 @@ def set_dsn(self, dsn=None, transport=None):

self.logger.debug("Configuring Raven for host: {0}".format(self.remote))

def install_sys_hook(self):
def install_sys_hook(self, skip_for_tty=True):
global __excepthook__

if __excepthook__ is None:
__excepthook__ = sys.excepthook

def handle_exception(*exc_info):
self.captureException(exc_info=exc_info, level='fatal')
if not skip_for_tty:
capture = True
else:
try:
capture = not sys.stdin.isatty()
except Exception:
capture = True
if capture:
self.captureException(exc_info=exc_info, level='fatal')
__excepthook__(*exc_info)
handle_exception.raven_client = self
sys.excepthook = handle_exception
Expand Down
23 changes: 23 additions & 0 deletions tests/base/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,3 +585,26 @@ def test_no_sys_argv(self):
Client()
finally:
sys.argv = argv

def test_sys_hook(self):
client = TempStoreClient(install_sys_hook=True)
try:
1 / 0
except Exception:
sys.excepthook(*sys.exc_info())

event = client.events.pop(0)
exc = event['exception']['values'][-1]
assert exc['type'] == 'ZeroDivisionError'
assert not client.events

sys.stdin.isatty = lambda: True
try:
try:
1 / 0
except Exception:
sys.excepthook(*sys.exc_info())

assert not client.events
finally:
del sys.stdin.isatty