GithubHelp home page GithubHelp logo

sanic-org / tracerite Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 4.0 1.03 MB

Tracebacks for Humans (in Jupyter notebooks)

License: The Unlicense

Python 82.29% CSS 17.71%
python jupyter traceback public-domain

tracerite's Introduction

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.

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

TraceRite 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, TraceRite produces scrollable outputs that concentrate on the relevant details but also provide variable inspectors on each frame where it may be relevant:

Nested exceptions TraceRite output with nested exceptions.

Usage

At the beginning of your Notebook:

%pip install tracerite
%load_ext tracerite

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.

tracerite's People

Contributors

ahopkins avatar thewchan avatar tronic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tracerite's Issues

Clicking on tab headers sometimes has no effect

For unknown reasons, the scroll function gets broken at times. Scrolling the page around a bit seems to fix it. Sideways scroll (if available on user device) can also be used to browse frames.

Need to look into the Javascript function and why it does nothing.

TypeError: vars() argument must have __dict__ attribute

When having an exception, the call to vars(value).items() fails with an exception in inspector.py at line 42:

Traceback (most recent call last):
File "/home/cx42/www/getfernand.com/api/env/lib64/python3.10/site-packages/tracerite/inspector.py", line 42, in extract_variables
for n, v in vars(value).items():
TypeError: vars() argument must have dict attribute

setuptools dependency

Seeing this error:

.venv/lib/python3.11/site-packages/sanic/errorpages.py:26: in <module>
    from sanic.pages.error import ErrorPage
.venv/lib/python3.11/site-packages/sanic/pages/error.py:3: in <module>
    import tracerite.html
.venv/lib/python3.11/site-packages/tracerite/__init__.py:1: in <module>
    from .html import html_traceback
.venv/lib/python3.11/site-packages/tracerite/html.py:1: in <module>
    import pkg_resources
E   ModuleNotFoundError: No module named 'pkg_resources'

Installing setuptools resolves this

The library was previously installed but when I did a poetry update it got uninstalled

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.