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

colors are missing on (Base)ExceptionGroup tracebacks in the pyrepl #125593

Closed
graingert opened this issue Oct 16, 2024 · 4 comments
Closed

colors are missing on (Base)ExceptionGroup tracebacks in the pyrepl #125593

graingert opened this issue Oct 16, 2024 · 4 comments
Assignees
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@graingert
Copy link
Contributor

graingert commented Oct 16, 2024

Bug description:

import sys

class InvalidFruitException(Exception):
    pass


def eat_fruit(fruit):
    if fruit == "banana":
        raise InvalidFruitException("no herbs please, only fruit")
    if fruit == "rock":
        raise InvalidFruitException("too tough")


def demo_continue_loop():
    food = ["apple", "rock", "orange", "banana"]
    exceptions = []
    try:
        for i, f in enumerate(food):
            try:
                eat_fruit(f)
            except Exception as e:
                e.add_note(f"failed on loop {i=} {f=}")
                exceptions.append(e)
        if exceptions:
            raise ExceptionGroup("multiple errors eating food", exceptions)
    finally:
        del exceptions  # no refcycles please!

def main():
    demo_continue_loop()
    return 0

if __name__ == "__main__":
    sys.exit(main())

here's the output:
https://asciinema.org/a/681263
681263

I'd expect the eat_fruit() parts to be highlighted in red

CPython versions tested on:

3.13, 3.14

Operating systems tested on:

Linux, macOS

This was added in #112730 but it looks like ExceptionGroups were missed

Linked PRs

@graingert graingert added type-bug An unexpected behavior, bug, or error 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Oct 16, 2024
@graingert graingert changed the title colors are missing on ExceptionGroup tracebacks colors are missing on ExceptionGroup tracebacks in the pyrepl Oct 16, 2024
@Eclips4
Copy link
Member

Eclips4 commented Oct 16, 2024

@graingert are you working on this issue? If not, @wrongnull would like to take this one :)

@graingert
Copy link
Contributor Author

@Eclips4 no I've not looked into it yet

@graingert graingert changed the title colors are missing on ExceptionGroup tracebacks in the pyrepl colors are missing on (Base)ExceptionGroup tracebacks in the pyrepl Oct 16, 2024
@graingert
Copy link
Contributor Author

one minor request I have is that exception notes have a color distinct to exception messages

@wrongnull
Copy link
Contributor

I'm working on this and found a fix. The pull request will be sent tomorrow

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 27, 2024
…s from exception group (pythonGH-125681)

(cherry picked from commit 51b012b)

Co-authored-by: Bogdan Romanyuk <[email protected]>
pablogsal pushed a commit that referenced this issue Oct 27, 2024
…ks from exception group (GH-125681) (#126021)

gh-125593: Use colors to highlight error locations in tracebacks from exception group (GH-125681)
(cherry picked from commit 51b012b)

Co-authored-by: Bogdan Romanyuk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants