skorokithakis / tbvaccine

A small utility to pretty-print Python tracebacks. ⛺

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Python 3's 'raise Exception from e'?

dsully opened this issue · comments

It's not clear if tbvaccine supports Python 3's 'raise MyException from e' syntax.

Or at least the original exception is not being emitted in the tbvaccine output.

Hmm yes, you're right, currently we're printing the last stack frame. This needs to be changed so TBV is more intelligent about which frame it prints.

more intelligent about which frame it prints.

Surely it should print them all?

It shouldn't expand frames that aren't a part of your program, and doesn't currently.

Let me be clearer. Consider this script:

try:
    1 / 0
except:
    foo

By default it outputs:

Traceback (most recent call last):
  File "/home/alex/.config/JetBrains/PyCharm2020.2/scratches/scratch_856.py", line 6, in <module>
    1 / 0
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/alex/.config/JetBrains/PyCharm2020.2/scratches/scratch_856.py", line 8, in <module>
    foo
NameError: name 'foo' is not defined

This contains two tracebacks. Previously it sounded like you were referring to tracebacks as frames, so I just went with it. Each traceback here contains one frame.

tbvaccine only shows the last traceback:

Traceback (most recent call last):
  File "/home/alex/.config/JetBrains/PyCharm2020.2/scratches/scratch_856.py", line 8, in <module>
>   foo
NameError: name 'foo' is not defined

Presumably tbvaccine should print every traceback so that users know what went wrong, although it can be selective about which frames it prints/expands within each traceback.

Also note that this example doesn't use the raise from syntax.

Oh, I see. Yes, it definitely shouldn't swallow tracebacks, this is a bug.