Open vanschelven opened 2 days ago
I think you should open a Discourse (https://discuss.python.org/c/ideas/6) post for this feature that seems non-trivial to implement. If you want a discussion, this is the place to go!
I like the idea, but yeah, this needs to get approved and bikeshedded on DPO first. Let’s leave this issue open in the meantime, though.
Feature or enhancement
Proposal:
Problem: When dealing with chained exceptions in Python, there is no straightforward way to identify the "outermost handling frame": the frame in the except/finally block that starts the part of the stacktrace that's unique to the "during the handling" exception.
This information is not visible in the textual stacktrace, nor is it accessible programmatically via Python's
traceback
module (or similar tools).Since this "handling frame" represents half of the link between 2 exceptions when shown in "chained mode", the fact that this information is missing makes it very hard to see how 2 chained exceptions actually relate to each other.
Proposal: Extend Python's traceback-related modules (e.g.,
traceback
,sys.exc_info
) to expose handling frame information. This would allow developers and tools to programmatically determine where exceptions are caught and re-raised in the call stack.(It would seem to me that just changing the underlying datastructures leads to the least disruption in peoples' workflow, while still allowing for some users to extract the information if they need it)
Current Behavior:
Using the following example:
Running this code produces:
In this traceback, line 17 (
raise_another_exception()
) is the handling frame, but there is no direct way to programmatically extract this information.Proposed Improvement:
Enhance the traceback-related API(s) to expose handling frame information.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
I wrote extensively about this problem (as well as more generally about how confusing chained stacktraces can be) on my blog.
This is obviously not actually a discussion since it doesn't involve other people, but I do think it's useful context (and it's better to keep the longer story out of the feature-request)
Linked PRs