rich
rich copied to clipboard
Add support for "Exception.add_note(...)" (PEP 678)[REQUEST]
The note does not appear when console.print_exception(show_locals=True)
PEP 678 – Enriching Exceptions with Notes
Should be:
>>> 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
>>>
#1859 also kind of track this
We would very much like support for exception notes, only just now realized they weren't working for our users.
This issue can be closed. add_note is supported since https://github.com/Textualize/rich/commit/f19b246826d23ec14ee09edeedc5953c640792ed .
from master
python foo.py
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ rich/foo.py:5 in <module> │
│ │
│ 2 console = Console() │
│ 3 │
│ 4 try: │
│ ❱ 5 │ raise ValueError("This is a test error") │
│ 6 except ValueError as e: │
│ 7 │ e.add_note("note") │
│ 8 │ console.print_exception(show_locals=True) │
│ │
│ ╭────────────────────── locals ───────────────────────╮ │
│ │ console = <console width=166 ColorSystem.TRUECOLOR> │ │
│ │ e = ValueError('This is a test error') │ │
│ ╰─────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: This is a test error
[NOTE] note
using 13.9.4 the NOTE isn't shown on the bottom
repro
from rich.console import Console
console = Console()
try:
raise ValueError("This is a test error")
except ValueError as e:
e.add_note("note")
console.print_exception(show_locals=True)
I can confirm that this now works in the most recent release, thanks!