Skip to content
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

bpo-45292: [PEP 654] Update traceback display code to work with exception groups #29207

Merged
merged 27 commits into from
Nov 5, 2021

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Oct 25, 2021

@iritkatriel
Copy link
Member Author

This is almost exactly the same as I used for the PEP - I just removed the "with X sub-exceptions" line from the tracebacks because I think it clutters them and is not very useful.

@gvanrossum
Copy link
Member

This is almost exactly the same as I used for the PEP - I just removed the "with X sub-exceptions" line from the tracebacks because I think it clutters them and is not very useful.

Just be sure to update the PEP examples. :-)

@iritkatriel iritkatriel added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 25, 2021
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @iritkatriel for commit 2052c77 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 25, 2021
Python/pythonrun.c Outdated Show resolved Hide resolved
Python/traceback.c Outdated Show resolved Hide resolved
Include/traceback.h Outdated Show resolved Hide resolved
Include/traceback.h Outdated Show resolved Hide resolved
Lib/test/test_traceback.py Outdated Show resolved Hide resolved
Lib/test/test_traceback.py Outdated Show resolved Hide resolved
Lib/test/test_traceback.py Outdated Show resolved Hide resolved
Python/pythonrun.c Outdated Show resolved Hide resolved
Python/pythonrun.c Outdated Show resolved Hide resolved
Python/traceback.c Outdated Show resolved Hide resolved
@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Copy link
Contributor

@erlend-aasland erlend-aasland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round comments :) I'll take a new round on references and pointers later.

Python/pythonrun.c Outdated Show resolved Hide resolved
Python/traceback.c Outdated Show resolved Hide resolved
Python/traceback.c Outdated Show resolved Hide resolved
Python/traceback.c Outdated Show resolved Hide resolved
Python/traceback.c Outdated Show resolved Hide resolved
Python/pythonrun.c Outdated Show resolved Hide resolved
Python/pythonrun.c Outdated Show resolved Hide resolved
Python/pythonrun.c Outdated Show resolved Hide resolved
Python/pythonrun.c Outdated Show resolved Hide resolved
Python/pythonrun.c Outdated Show resolved Hide resolved
@1st1
Copy link
Member

1st1 commented Oct 27, 2021

Do you have an opinion on whether it's better to box all EG tracebacks or only the nested ones?

I think it's OK to always box the EGs because they're pretty special, although I'd change the very first line of the output, from:

    | Traceback (most recent call last):
    |   File "{__file__}", line {exc.__code__.co_firstlineno + 9}, in exc
    |     raise EG("eg", [VE(1), exc, VE(4)])
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | ExceptionGroup: eg
    +-+---------------- context.1 ----------------
        | ValueError: 1
        +---------------- context.2 ----------------
        | Traceback (most recent call last):
        |   File "{__file__}", line {exc.__code__.co_firstlineno + 6}, in exc
        |     raise EG("nested", [TE(2), TE(3)])
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        | ExceptionGroup: nested
        +-+---------------- context.2.1 ----------------
        | TypeError: 2
        +---------------- context.2.2 ----------------
        | TypeError: 3
        +------------------------------------
        +---------------- context.3 ----------------
        | ValueError: 4
        +------------------------------------

to:

    + Exception group traceback (most recent call last):
    |
    |   File "{__file__}", line {exc.__code__.co_firstlineno + 9}, in exc
    |     raise EG("eg", [VE(1), exc, VE(4)])
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | ExceptionGroup: eg
    +-+---------------- context.1 ----------------
        | ValueError: 1
        +---------------- context.2 ----------------
        | Traceback (most recent call last):
        |   File "{__file__}", line {exc.__code__.co_firstlineno + 6}, in exc
        |     raise EG("nested", [TE(2), TE(3)])
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        | ExceptionGroup: nested
        +-+---------------- context.2.1 ----------------
        | TypeError: 2
        +---------------- context.2.2 ----------------
        | TypeError: 3
        +------------------------------------
        +---------------- context.3 ----------------
        | ValueError: 4
        +------------------------------------

@iritkatriel
Copy link
Member Author

@1st1 - see below.

    + Exception group traceback (most recent call last):
    |
    |   File "{__file__}", line {exc.__code__.co_firstlineno + 9}, in exc
    |     raise EG("eg", [VE(1), exc, VE(4)])
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | ExceptionGroup: eg
    +-+---------------- context.1 ----------------
        | ValueError: 1
        +---------------- context.2 ----------------
        | Traceback (most recent call last):
        |   File "{__file__}", line {exc.__code__.co_firstlineno + 6}, in exc
        |     raise EG("nested", [TE(2), TE(3)])
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        | ExceptionGroup: nested
        +-+---------------- context.2.1 ----------------

The indentation of the next line is wrong. Is this a copy-paste error or a bug?

    | TypeError: 2
    +---------------- context.2.2 ----------------
    | TypeError: 3
    +------------------------------------
    +---------------- context.3 ----------------
    | ValueError: 4
    +------------------------------------

@1st1
Copy link
Member

1st1 commented Oct 27, 2021

The indentation of the next line is wrong. Is this a copy-paste error or a bug?

Copy/paste/whitespace issue; no implementation bugs were observed!

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the max_group_{with,depth} solution and the refactor of the chaining loop!

I didn't review the C code carefully, it looks like others are on that.

The only things left from me are nits in the formatting of some of the overflow messages. Otherwise LGTM!

Lib/traceback.py Outdated Show resolved Hide resolved
Lib/traceback.py Outdated Show resolved Hide resolved
@iritkatriel iritkatriel added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 3, 2021
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @iritkatriel for commit 61fab3f 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 3, 2021
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG!

@iritkatriel
Copy link
Member Author

LG!

Thank you!

@gpshead @erlend-aasland @1st1 I'll wait a bit before merging in case you want to have another look.

Copy link
Contributor

@erlend-aasland erlend-aasland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good; great job!

The only remark I have is that I find the error handling verbose and hard to read. I'm used to (and prefer):

int
func()
{
    int rc = first();
    if (rc < 0) {
        goto error;
    }
    int err = second();
    if (err != 0) {
        goto error;
    }
    // etc.

    // at the end:
    return 0;
error:
    cleanup();
    return -1;
}

The current approach of always verifying that the previous step did not fail seems to lead to a lot of indenting levels. I could count 7 (!) indents in one of the functions.

I would consider simplifying the error handling for the sake of readability.

Feel free to disregard this comment; It's only personal preference :)

@iritkatriel
Copy link
Member Author

@erlend-aasland I agree with your comment. I tried using gotos but it was a bit delicate because you need to make sure the refcounting is still correct. This is a refactor that should be done in its own PR and not together with major functional changes. The current method preserves the control flow so it doesn't impact refcounts.

@erlend-aasland
Copy link
Contributor

This is a refactor that should be done in its own PR and not together with major functional changes.

+1 🙂

@iritkatriel
Copy link
Member Author

Thank you everyone for your help!

@iritkatriel iritkatriel merged commit 3509b26 into python:main Nov 5, 2021
@iritkatriel iritkatriel deleted the bpo-45292-traceback branch November 5, 2021 09:48
# format exception group
is_toplevel = (_ctx.exception_group_depth == 0)
if is_toplevel:
_ctx.exception_group_depth += 1
Copy link
Member

@merwok merwok Jan 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI running patchcheck for an unrelated PR just complained about this 5-space indent!
(and more in Lib/traceback.py)

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 this pull request may close these issues.

8 participants