skorokithakis / tbvaccine

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

ipython integration #24

Open nixjdm opened 5 years ago

nixjdm commented 5 years ago

There's at least a couple problems with this working with ipython.

  1. Exporting the env var seems to have no effect.
  2. This brings the formatting of tbvaccine, and some things, but not the locals I added in the shell.
    from tbvaccine import TBVaccine 
    try:
    some_stuff()
    except:
    print(TBVaccine().format_exc())

    imagine this is styled:

    
    Traceback (most recent call last):
    File "<ipython-input-2-6c94a79ed40f>", line 4, in <module>
    >   some_stuff()
    |     __annotations__ = {}
    |     __builtins__    = <module 'builtins' (built-in)>
    |     __cached__      = None
    |     __doc__         = None
    |     __file__        = [path to]/bin/ipython
    |     __loader__      = <_frozen_importlib_external.SourceFileLoader object at 0x7f880a16fc88>
    |     __name__        = __main__
    |     __package__     = None
    |     __spec__        = None
    |     re              = <module 're' from '[path to]/lib/python3.6/re.py'>
    |     start_ipython   = <function start_ipython at 0x7f88069a18c8>
    |     sys             = <module 'sys' (built-in)>
    NameError: name 'some_stuff' is not defined

3. This seems to not be any different from a normal exception in ipython. It looks identical either way.
```python
import tbvaccine
tbvaccine.add_hook(isolate=False)

1 / 0

The same seems to hold for at least flask-shell-ipython, which is unsurprising.

Possibly out-of-scope: I have no idea really, but maybe whatever is needed to get this to work would also suffice for Jupyter as well. If we're lucky.

skorokithakis commented 5 years ago

Yeah, this is flaky enough that I ended up not using it myself, but also useful enough that I really should look into it and see why it doesn't work. I would expect that the global system hook would pretty-print any exception, but that doesn't seem to work either.

nixjdm commented 5 years ago

The addition of printing locals is the selling point for me :) That's a large part of why Sentry is great too. It can make debugging a ton easier.

skorokithakis commented 5 years ago

Definitely agreed, it's a great tool, if I can get it working :P

alexmojaki commented 4 years ago

It's not well advertised, but you can make ipython show local variables by running %xmode Verbose. https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-xmode

ipython tracebacks will also be improved with the release of 8.0, e.g. see https://github.com/ipython/ipython/pull/12150