Skip to main content

Nicer error messages for Python

Other languages such as C++ have gotten quite useful error messages and diagnostics with tips on how the fix the problems but Python is still stuck with the bare stacktraces that are very intimidating and often not very helpful.

Niceback Niceback backtrace shows where the user has terminated the program.

Niceback hides the irrelevant IPython/notebook internals and concisely shows what happened (the program was interrupted) and where that happened. This could further be improved by converting the KeyboardInterrupt message into something more suitable, like "You stopped the program", but what you see above is just the default handling that never considered this particular error.

Although IPython and Google Colab developers have done their tweaks to improve backtraces, it is all too apparent that much remains to be done:

Colab Standard backtrace from Google Colab.

Even for the experienced programmer, it is tedious to read through the wall of text to find the relevant details of what went wrong.

In more complex situations where one might get many screenfuls of standard traceback, Niceback produces scrollable outputs that concentrate on the relevant details but also provide variable inspectors on each frame where it may be relevant:

Nested exceptions Niceback output with nested exceptions.

Usage

At the beginning of your Notebook:

!pip install niceback
%load_ext niceback

Background

This project is a proof of concept, showing a modern way to format error messages in a human-readable manner. Heuristics are used to hide (by default) irrelevant stack frames and show the actual location of the problem. Since it would otherwise be impossible to find out the variable contents after the program has crashed, a variable inspector built into each stack frame quickly reveals problems with the variables mentioned at the source of error. Care is taken to add revelant details such as notebook input field numbers and class names not normally present in Python tracebacks, while hiding overly long paths and other clutter.

All output is in HTML and as such only works in Jupyter notebooks and other browser-based systems (this should be useful for web development frameworks as well). This allows interactivity and much better layout than that of the text console.

License

Public Domain or equivalent.

Help wanted

I won't be able to maintain this all by myself. If you like the idea of nicer tracebacks, please offer your help in development! Pull requests are welcome but it would be even better if you could pick up the whole project as your own.

As of now, this project is in no way properly polished for release. Yet, it is useful enough to such a degree that I always use it in my notebooks, and it really makes Python development a much smoother experience.

Metadata

Release files for niceback 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for niceback 0.4.2
File Size Uploaded
niceback-0.4.2.tar.gz 594.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for niceback 0.4.2
File Interpreter ABI Platform
niceback-0.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 604.3 kB

Release files / niceback-0.4.2.tar.gz

Download URL niceback-0.4.2.tar.gz
Size 594.3 kB
Tags Source
SHA-256 checksum
How to use checksums
003aea4eeea1a57bd35fa84953c830b5dc36b00754c75dcbaefee41f72e11cdd
BLAKE2b-256 checksum
How to use checksums
93077d71ed7db3afe919a2faf5033014572dfa64f70326d929b7d83c68fc42eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.10

Release files / niceback-0.4.2-py3-none-any.whl

Download URL niceback-0.4.2-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17bc6626f67b88c455ca6976b0f9c03a9da74f414e47534375df82fd4fdc9271
BLAKE2b-256 checksum
How to use checksums
a1ef4759be65a3e830283f3a3bdc014de152ff91ef9ace3d723410856fe0e7d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.4.1

2 release files

0.4.0

1 release file

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page