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

[BUG] Traceback handler does supress context #468

Closed
beanaroo opened this issue Dec 6, 2020 · 0 comments · Fixed by #480
Closed

[BUG] Traceback handler does supress context #468

beanaroo opened this issue Dec 6, 2020 · 0 comments · Fixed by #480

Comments

@beanaroo
Copy link

beanaroo commented Dec 6, 2020

Describe the bug
PEP 409 allows you to suppress exception context. This does not appear to have an effect after installing the rich traceback handler.

To Reproduce

from rich import traceback
traceback.install()

try:
    foo = os.environ['FOO']
except KeyError:
    raise Exception('Environment not configured. Missing FOO setting.') from None

Output (without handler)

Traceback (most recent call last):
  File "/home/beanaroo/Projects/foo/main.py", line 98, in <module>
    raise Exception('Environment not configured. Missing FOO setting.') from None
Exception: Environment not configured. Missing FOO setting.

Output (with handler)

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/beanaroo/Projects/foo/main.py:676 in __getitem__                                           │
│                                                                                                  │
│    673 │                                                                                         │
│    674 │   def __getitem__(self, key):                                                           │
│    675 │   │   try:                                                                              │
│ ❱  676 │   │   │   value = self._data[self.encodekey(key)]                                       │
│    677 │   │   except KeyError:                                                                  │
│    678 │   │   │   # raise KeyError with the original key value                                  │
│    679 │   │   │   raise KeyError(key) from None                                                 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: b'FOO'

During handling of the above exception, another exception occurred:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/beanaroo/Projects/foo/main.py:96 in <module>                                               │
│                                                                                                  │
│    93 traceback.install()                                                                        │
│    94                                                                                            │
│    95 try:                                                                                       │
│ ❱  96 │   foo = os.environ['FOO']                                                                │
│    97 except KeyError:                                                                           │
│    98 │   raise Exception('Environment not configured. Missing FOO setting.') from None          │
│    99                                                                                            │
│                                                                                                  │
│ /home/mike/.pyenv/versions/3.9.0/lib/python3.9/os.py:679 in __getitem__                          │
│                                                                                                  │
│    676 │   │   │   value = self._data[self.encodekey(key)]                                       │
│    677 │   │   except KeyError:                                                                  │
│    678 │   │   │   # raise KeyError with the original key value                                  │
│ ❱  679 │   │   │   raise KeyError(key) from None                                                 │
│    680 │   │   return self.decodevalue(value)                                                    │
│    681 │                                                                                         │
│    682 │   def __setitem__(self, key, value):                                                    │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: 'FOO'

During handling of the above exception, another exception occurred:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/beanaroo/Projects/foo/main.py:98 in <module>                                               │
│                                                                                                  │
│    95 try:                                                                                       │
│    96 │   foo = os.environ['FOO']                                                                │
│    97 except KeyError:                                                                           │
│ ❱  98 │   raise Exception('Environment not configured. Missing FOO setting.') from None          │
│    99                                                                                            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
Exception: Environment not configured. Missing FOO setting.

Alternative

from rich import traceback
traceback.install()

try:
    bar = os.environ['BAR']
except KeyError as err:
    raise Exception('A problem occurred when setting up bar') from err

Expected Output

The above exception was the direct cause of the following exception:

Actual Output

During handling of the above exception, another exception occurred:

Platform
Python 3.9.0 venv on Arch Linux with Rich 9.3.0 using any terminal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant