-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Post mortem debugging of the inner exception in exception chain #1042
Comments
To clarify, do you expect to see the stack trace at the point where the original exception was raised? Kinda like what happens when an exception is raised and not caught anywhere? |
def fail():
raise Exception(1)
try:
fail()
except Exception as e:
raise Exception(2) from e Normally, when debugging the above snippet in vscode, the breakpoint will hit on the last line (Uncaught exception). This is already reasonable behavior, but I recently found that it's also possible to debug the inner exception (on the second line). A chained exception is often used to transform error messages or do some extra logging before exiting (This is an unverified statement). Thus, it's desirable to have support for switching to the inner (maybe more than one) exception. I'm not familiar with the DAP and not sure if it could be implemented similar to different threads in the stacktrace panel. Also, providing a dropdown menu to select along the exception chain. P.S.: My current workaround is to avoid chained exception, but reraise the original exception and printing message before reraising. |
Looking at the DAP spec, there's "innerException", but it looks like we deliberately don't set it: debugpy/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py Lines 1510 to 1511 in 3272dac
However, this was 2 years ago, so we should revisit and see if it works now. |
I might be mistaken, but a simple grep through the vscode repository with "innerExceptions" only shows one occurence which is the definition. I'm not sure whether passing this could take effect. |
You're right; looks like this is only supported by VS right now and not by VSCode, so the latter needs a feature request to implement that support (and we'll need to talk about UX at that point). But in the meantime, we can start supplying it to light up any client that does support it. |
Passing "innerException" doesn't break VSCode, although, as expected, it also doesn't do anything useful. However, it is indeed supported by VS, although that just causes it to show both exceptions in the popup. |
Maybe we could just add the additional frames to the existing frame stack (so, it'd be possible to get to that context regardless of the I'll take a look at this to check if the final result is reasonable. |
#1057 implements a great feature to "show" the stacktrace of chained exception, but I'm not sure if it's easily possible to inspect the frames as we move into some frames of the inner exception. How can I do this? debugpy gives me: |
I don't think it would be possible to do an eval in the chained frames. That frame is gone and hence there's nowhere to run the evaluation. In this example, I believe you're talking about evaling the value of say def fail():
x = 4
raise Exception(1) # Chained exception generated here
try:
fail()
except Exception as e:
raise Exception(2) from e # Breakpoint fires here |
The traceback object (accessible via I'm not entirely sure why the eval needs to be done on that thread specifically, but I suspect this has to do with the possibility that it is holding some locks, and thus eval from a different thread might deadlock? |
As is suggested in Pdb go to a frame in exception within exception, calling
pdb.post_mortem
on the__context__
of a chained exception gives a chance to debug the inner exception, and this could be nested. A minimal snippet would beBut in vscode, I did not find a way to debug the inner exception from the
raise Exception(2) from e
line. I wonder whether this feature could be implemented.The text was updated successfully, but these errors were encountered: