Better handling of exception groups#4164
Conversation
|
(The diff is very hard to read, just check out the whole file to make your live easier) The function (We can in another PR also think about removing |
❌ 872 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
szokeasaurusrex
left a comment
There was a problem hiding this comment.
@antonpirker I am still struggling a bit to see how the behavior is supposed to change here. Can you walk me through this on Thursday?
sentrivana
left a comment
There was a problem hiding this comment.
special thanks for the comments, very helpful in understanding what's going on
szokeasaurusrex
left a comment
There was a problem hiding this comment.
Please review my comments before merging
| # make sure the exceptions are sorted | ||
| # from the innermost (oldest) | ||
| # to the outermost (newest) exception | ||
| exceptions.reverse() |
There was a problem hiding this comment.
[optional – can also address in a later PR or wait and see if it is actually a problem in the real world]
Per our offline discussion, please check whether it would be possible to construct the exceptions list (within exceptions_from_error) in the correct order, so that reversing here is unnecessary.
Reason it would be better to construct in the opposite order is that exceptions_from_error on each recursive call is appending all of the exceptions to a list containing the base exception (an O(n) operation). Since we call exceptions_from_error O(n) times, this makes the function potentially O(n^2). If instead, we simply take the array from the recursive call, and then append to that array, I believe we solve this potential problem.
If it is too much effort to address here, let's just merge the PR for now, assuming exception chains are usually small, this won't matter much anyways.
There was a problem hiding this comment.
Because exception chains are not that long on average in my opinion it is not worth the effort and also the decline in readability of the code to make this change now.
…m:getsentry/sentry-python into antonpirker/fix/exception-groups-on-potel
Properly handle grouped and chained exceptions. The test case in the linked issue illustrates that some ExceptionGroups have been handled in a wrong way.
Updated some tests, because now that those are handled correctly all the mechanism types except for the root exception are set to "chained" like described in the RFC: https://github.com/getsentry/rfcs/blob/main/text/0079-exception-groups.md#interpretation
Because this will change the grouping of exiting Sentry Issues containing ExceptionGroups, it is safer to release this fix in the next major and make sure that we describe the change in behavior in the changelog. (Note: The grouping in the Ariadne issues will not change because those are not ExceptionGroups and only updating the
mechanism.typedoes not change the grouping)The main change is the
exceptions_from_errorfunction:sentry-python/sentry_sdk/utils.py
Lines 790 to 890 in 72f3f84
Fixes #3913