ice icon indicating copy to clipboard operation
ice copied to clipboard

Suggestion: optional rich tracebacks

Open alexmojaki opened this issue 2 years ago • 4 comments

Currently an unhandled exception just shows the standard plain Python traceback. It can be helpful for debugging to show more information, and the dependencies are already there. One method is this:

    log = get_logger()

    def excepthook(*exc_info):
        log.exception("Uncaught exception", exc_info=exc_info)

    sys.excepthook = excepthook

However this doesn't work on its own, and a helpful warning explains why:

/code/.venv/lib/python3.10/site-packages/structlog/dev.py:421: UserWarning: Remove `format_exc_info` from your processor chain if you want pretty exceptions.

Indeed, removing that processor gives nice rich tracebacks:

Screenshot from 2022-09-22 14-51-17

I'm not familiar with structlog, maybe there's a better official way to do this. I also don't know the motivation for having format_exc_info and the consequences of removing it.

An alternative, more direct approach:

rich.traceback.install(show_locals=True)

This has pretty much the same effect, but it's not logging, and maybe that's a problem.

None of this should be the default behaviour as the tracebacks are huge and annoying when you don't want them, but maybe it could be enabled by a new env var in settings.py or some kind of verbose/debug CLI argument.

alexmojaki avatar Sep 22 '22 13:09 alexmojaki

We're not actually using the structured logging for anything, so this is probably the way to go. I'll determine priority next week once the upcoming ICE release is done.

lslunis avatar Sep 23 '22 20:09 lslunis

I'm happy to take this on if people think this is still valuable :)

smithjessk avatar Jan 30 '23 17:01 smithjessk

Seems worthwhile, what do you think @alexmojaki ?

lslunis avatar Jan 31 '23 23:01 lslunis

Sure, why not.

alexmojaki avatar Feb 01 '23 09:02 alexmojaki