skorokithakis / tbvaccine

A small utility to pretty-print Python tracebacks. ⛺
MIT License
377 stars 14 forks source link

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

Open dsully opened 6 years ago

dsully commented 6 years ago

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.

skorokithakis commented 6 years ago

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.

alexmojaki commented 4 years ago

more intelligent about which frame it prints.

Surely it should print them all?

skorokithakis commented 4 years ago

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

alexmojaki commented 4 years ago

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.

skorokithakis commented 4 years ago

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