Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ipdb: support for chained exceptions #13982

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

Closed
mlucool opened this issue Mar 23, 2023 · 4 comments · Fixed by #14146
Closed

ipdb: support for chained exceptions #13982

mlucool opened this issue Mar 23, 2023 · 4 comments · Fixed by #14146
Assignees

Comments

@mlucool
Copy link

mlucool commented Mar 23, 2023

This is a common pattern to enrich an exception with more information:

def foo(x):
    try:
        bar(x)
    except Exception as e:
        raise ValueError("foo(): bar failed") from e
def bar(x):
    1/x

This is common when a second exception occurs during exception handling:

def foo(x):
    try:
        bar(x)
    except Exception as e:
        raise ValueError("some other error")
def bar(x):
    1/x

In both cases, ipdb (and pdb) wont let us step up the stack from to find the error in bar. While python 3.11 has Exception.add_note, there will continue to be lots of code using the methods above (and its not always practical to use this).

Example:
image

Can we enhance ipdb to handle both cases?

@Carreau Carreau self-assigned this Jul 11, 2023
@Carreau
Copy link
Member

Carreau commented Jul 11, 2023

Apologies for the late reply to this issue. After a bit of investigating it should be possible with some refactor; I believe in both case.

One limitation is that pdb get a Traceback by default instead of a full Exception and you can go from Exception to TB but not the other way around.

I can mess around with the internal state of pdb when you do up (from the oldest frame), or down ( from the Newest frame), and jump to the __context__ (or __cause__ of raise ...from) it seem to work, at least on the surface.

@Carreau
Copy link
Member

Carreau commented Jul 11, 2023

@Carreau
Copy link
Member

Carreau commented Jul 18, 2023

See discussion in python/cpython#106670 as well.

Carreau added a commit to Carreau/ipython that referenced this issue Aug 29, 2023
Closes ipython#13982

This is a "backport" of python/cpython#106676

See documentation there
@Carreau
Copy link
Member

Carreau commented Aug 29, 2023

This is now in CPython main branch and will part of Python 3.13 if all is well,
I'm working on backporting the change to IPython to have it in earlier Python version.

Carreau added a commit to Carreau/ipython that referenced this issue Aug 29, 2023
Closes ipython#13982

This is a "backport" of python/cpython#106676

See documentation there
Carreau added a commit that referenced this issue Aug 29, 2023
Closes #13982

This is a "backport" of python/cpython#106676

See documentation there
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants