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

Add support for "Exception.add_note(...)" (PEP 678) #505

Open
7 tasks done
libexpand opened this issue Nov 16, 2022 · 2 comments
Open
7 tasks done

Add support for "Exception.add_note(...)" (PEP 678) #505

libexpand opened this issue Nov 16, 2022 · 2 comments
Labels
feature New feature, enhancement or request investigate

Comments

@libexpand
Copy link

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Typer documentation, with the integrated search.
  • I already searched in Google "How to X in Typer" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to Typer but to Click.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

>>> try:
...     raise TypeError('bad type')
... except Exception as e:
...     e.add_note('Add some information')
...     raise
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
TypeError: bad type
Add some information
>>>

Description

The note does not appear when pretty_exceptions_enable=True
PEP 678 – Enriching Exceptions with Notes

Wanted Solution

I would like the note to appear when pretty exceptions are enabled.

Wanted Code

try:
    raise TypeError('bad type')
except Exception as e:
    e.add_note('Add some information')
    raise

Alternatives

No response

Operating System

Linux, Windows

Operating System Details

No response

Typer Version

0.7.0

Python Version

Python 3.11.0

Additional Context

No response

@libexpand libexpand added the feature New feature, enhancement or request label Nov 16, 2022
@ESPR3SS0
Copy link

The notes are only omitted when rich is installed. When rich is not installed the notes are included.

So it looks like the notes are omitted by rich.Console in the function 'print_exception', and therefore not something typer could directly fix.

As a work-around Typer could manually print the notes until rich.Console implements it. I wouldn't mind looking into this if this behavior is desired.

@peterjc
Copy link

peterjc commented Oct 24, 2024

This was logged with Rich as Textualize/rich#2652

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature, enhancement or request investigate
Projects
None yet
Development

No branches or pull requests

4 participants