One of my goals in writing Rich was to render really nice Python tracebacks. And now that feature has landed.
I've never found Python tracebacks to be a great debugging aid beyond telling me what the exception was, and where it occurred. In a recent update to Rich, I've tried to refresh the humble traceback to give enough context to diagnose errors before switching back to the editor.
Here's an example of a rich traceback:
There is highlighting to help pick out filename, line, and function, etc. There's also a snippet of code for each stack frame, with line numbers and syntax highlighting. It's configurable, but I find that 7 lines of code are enough to make it relatable to the file in my editor, and give me a better understanding of the context that lead to the exception.
Here's how tracebacks render on Windows:
For reference, here's the same traceback rendered in a more traditional way:
To try out rich tracebacks, install the exception handler as follows:
from rich.traceback import install install()
Now any uncaught exceptions will rendered by Rich. See the docs for details.
Rich is quite usable as a library now, but is still in active development. If you have any ideas on how to improve rich tracebacks or any other aspect of the library, let me know.