question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception chaining

See original GitHub issue

I would like to be able to have sentry display the original exception in the chain. In a lot of places we do something like this:

try:
    v = {}['a']
except KeyError as e:
    raise ValueError('failed') from e

I would like to be able to get at the KeyError in sentry just like the output of python when this code is ran:

Traceback (most recent call last):
  File "t.py", line 2, in <module>
    v = {}['a']
KeyError: 'a'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "t.py", line 4, in <module>
    raise ValueError('failed') from e
ValueError: failed

Is this possible in raven?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:5
  • Comments:25 (18 by maintainers)

github_iconTop GitHub Comments

6reactions
kiwiholmbergcommented, May 25, 2016

Would very much like this functionality!

1reaction
cjerdonekcommented, Jan 22, 2018

I haven’t noticed any issues with Sentry’s aggregation of chained exceptions.

@phillbaker This is what you should be doing to take advantage of the client’s support for chaining:

try:
    requests.get("http://example.com")
except requests.exceptions.ConnectionError:
     raise MylibError("Unable to connect")

That way Python chains the ConnectionError to MylibError (and Sentry will render it), and Sentry will aggregate only on the info of what you pass to MylibError’s constructor.

Doing raise MylibError("Unable to connect", e) from None breaks this because (1) including from None breaks the chain (and so losing information from Sentry’s rendering), and (2) it includes the ConnectionError object in the constructor, which I could see causing Sentry not to aggregate different MylibError objects.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chained Exceptions in Java - Baeldung
Chained Exception helps to identify a situation in which one exception causes another Exception in an application. For instance, consider a ...
Read more >
Chained Exceptions - The Java™ Tutorials - Oracle Help Center
An application often responds to an exception by throwing another exception. In effect, the first exception causes the second exception. It can be...
Read more >
Exception chaining - Wikipedia
Exception chaining, or exception wrapping, is an object-oriented programming technique of handling exceptions by re-throwing a caught exception after ...
Read more >
Chained Exceptions in Java - GeeksforGeeks
Chained Exceptions allows to relate one exception with another exception, i.e one exception describes cause of another exception.
Read more >
What is exception chaining in Java? - Educative.io
Exception chaining occurs when one exception causes another exception. The original exception is the cause of the second exception.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found