GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-45292: [PEP 654] Update traceback display code to work with exception groups by iritkatriel · Pull Request #29207 · python/cpython

Conversation

@iritkatriel

@iritkatriel iritkatriel commented Oct 25, 2021 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

https://bugs.python.org/issue45292

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
iritkatriel added 4 commits October 25, 2021 10:55
@iritkatriel
C traceback code
42bed01
@iritkatriel
add ExceptionGroups support to traceback.py
a2daa23
@iritkatriel
remove 'with X sub-exceptions' line from tracebacks
261917a
@iritkatriel
pass margin instead of margin_char
7613b43
@iritkatriel
iritkatriel requested review from 1st1, Yhg1s, erlend-aasland, gpshead and gvanrossum October 25, 2021 10:24
@bedevere-bot bedevere-bot added the awaiting core review label Oct 25, 2021
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Oct 25, 2021
@iritkatriel
update news
d98a72b
@iritkatriel

iritkatriel commented Oct 25, 2021

Copy link
Copy Markdown
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.

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel added 3 commits October 25, 2021 13:14
@iritkatriel
excs is tuple, use PyTuple apis. Change check to assertion.
d69916e
@iritkatriel
remove redundant num_excs > 0 check (it is asserted above)
f5cab69
@iritkatriel
remove cpython_only from exception group tests
5170f00
@gvanrossum

gvanrossum commented Oct 25, 2021

Copy link
Copy Markdown
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 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iritkatriel
handle recursion errors (vert deeply nested EGs)
2052c77
@iritkatriel iritkatriel added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 25, 2021
@bedevere-bot

bedevere-bot commented Oct 25, 2021

Copy link
Copy Markdown

🤖 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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 25, 2021
gpshead
gpshead requested changes Oct 26, 2021
View reviewed changes
Comment thread Python/pythonrun.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/traceback.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Include/traceback.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Include/traceback.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/pythonrun.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/pythonrun.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/traceback.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting core review label Oct 26, 2021
@bedevere-bot

bedevere-bot commented Oct 26, 2021

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added the awaiting changes label Oct 26, 2021
erlend-aasland
erlend-aasland reviewed Oct 26, 2021
View reviewed changes

@erlend-aasland erlend-aasland left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Python/pythonrun.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/traceback.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/traceback.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/traceback.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/traceback.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/pythonrun.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/pythonrun.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/pythonrun.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/pythonrun.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/pythonrun.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel added 4 commits October 26, 2021 11:20
@iritkatriel
WRITE_INDENTED_MARGIN macro --> write_indented_margin function
5097300
@iritkatriel
move new traceback utils to internal/
dc21cf8
@iritkatriel
test improvements
d4007b7
@iritkatriel
pep7, improve error checking and clarity
169934e
@1st1

1st1 commented Oct 27, 2021

Copy link
Copy Markdown
Member

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
        +------------------------------------
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iritkatriel

iritkatriel commented Oct 27, 2021

Copy link
Copy Markdown
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
    +------------------------------------
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@1st1

1st1 commented Oct 27, 2021

Copy link
Copy Markdown
Member

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!

iritkatriel reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel added 9 commits October 29, 2021 17:31
@iritkatriel
remove full-path labels
5c1015d
@iritkatriel
int --> bool
83abebd
@iritkatriel
move code around
16d077d
@iritkatriel
Tweak the top-level of traceback box as suggested by Yury
64fb164
@iritkatriel
tidy up error handling
88019f5
@iritkatriel
add limits for width and depth of formatted exception groups
e963835
@iritkatriel
use _PyBaseExceptionGroup_Check macro
e85510a
@iritkatriel
remove redundant PyErr_Clear
c15a7bd
@iritkatriel
minor tweak - move if out of loop
d8cc6e8
gvanrossum
gvanrossum reviewed Nov 3, 2021
View reviewed changes

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this 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!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@iritkatriel
remove excess whitespace
61fab3f
@iritkatriel iritkatriel added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 3, 2021
@bedevere-bot

bedevere-bot commented Nov 3, 2021

Copy link
Copy Markdown

🤖 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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 3, 2021
gvanrossum
gvanrossum approved these changes Nov 4, 2021
View reviewed changes

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LG!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting change review labels Nov 4, 2021
@iritkatriel

iritkatriel commented Nov 4, 2021

Copy link
Copy Markdown
Member Author

LG!

Thank you!

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland
erlend-aasland reviewed Nov 4, 2021
View reviewed changes

@erlend-aasland erlend-aasland left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this 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 :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@iritkatriel

iritkatriel commented Nov 4, 2021

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland

erlend-aasland commented Nov 4, 2021

Copy link
Copy Markdown
Contributor

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

+1 🙂

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iritkatriel

iritkatriel commented Nov 5, 2021

Copy link
Copy Markdown
Member Author

Thank you everyone for your help!

erlend-aasland reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iritkatriel
iritkatriel merged commit 3509b26 into python:main Nov 5, 2021
@bedevere-bot bedevere-bot removed the awaiting merge label Nov 5, 2021
@iritkatriel
iritkatriel deleted the bpo-45292-traceback branch November 5, 2021 09:48
merwok
merwok reviewed Jan 3, 2022
View reviewed changes
Comment thread Lib/traceback.py
# format exception group
is_toplevel = (_ctx.exception_group_depth == 0)
if is_toplevel:
_ctx.exception_group_depth += 1

@merwok merwok Jan 3, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel and erlend-aasland reacted with heart emoji
All reactions
  • ❤️ 2 reactions
@iritkatriel iritkatriel mentioned this pull request Apr 10, 2022
Implement PEP 654: Exception Groups #89455
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@1st1 1st1 1st1 left review comments
@merwok merwok merwok left review comments
@erlend-aasland erlend-aasland erlend-aasland left review comments
@gvanrossum gvanrossum gvanrossum approved these changes
@Yhg1s Yhg1s Awaiting requested review from Yhg1s
@gpshead gpshead Awaiting requested review from gpshead

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@iritkatriel @gvanrossum @bedevere-bot @1st1 @erlend-aasland @gpshead @merwok @the-knights-who-say-ni
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.