explaingit

qix-/better-exceptions

4,729PythonAudience · developerComplexity · 1/5Setup · easy

TLDR

A Python package that replaces the default crash output with colorized stack traces showing the actual values of variables at the moment your code crashed, making bugs much easier to spot.

Mindmap

mindmap
  root((better-exceptions))
    What it does
      Colorized tracebacks
      Show variable values
      Readable crash output
    Setup
      pip install
      Set env variable
      No code changes
    Integrations
      Django middleware
      Python test runner
      Interactive shell
    Caution
      Disable in production
      Sensitive data risk
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Immediately see which variable held the bad value that caused a crash, without adding print statements.

USE CASE 2

Enable better error output globally for a Django web app via a middleware component.

USE CASE 3

Use colored, readable tracebacks in your test suite to make failing tests easier to diagnose.

Tech stack

Python

Getting it running

Difficulty · easy Time to first run · 5min

Disable before production deployment to avoid leaking sensitive variable values in logs or error pages.

In plain English

Better-exceptions is a Python package that makes error messages easier to read when something goes wrong in your code. By default, Python prints a stack trace when a crash happens, which shows you the sequence of function calls that led to the error, but it can be hard to parse. Better-exceptions reformats that output with colors and adds the actual values of variables at the moment the crash occurred, so you can see what data caused the problem without adding extra print statements. Setting it up is minimal. You install it through pip, Python's standard package manager, and then set a single environment variable to turn it on. After that, it activates automatically for any Python script you run, with no code changes needed. A security note in the README advises turning it off in production environments because printing variable values in logs can expose sensitive information like passwords or user data. The package works in several contexts beyond basic script execution. It can be used in the interactive Python shell, in Django web applications through a middleware component, and in Python's built-in testing framework. Each integration has slightly different setup instructions described in the README. If the improved output does not appear after setup, the README walks through common causes: the environment variable not being set permanently, another package overriding Python's error handler, or a supporting file getting accidentally deleted during updates.

Copy-paste prompts

Prompt 1
I installed better-exceptions and set the environment variable, but I'm still seeing plain Python tracebacks. What could be overriding it?
Prompt 2
How do I enable better-exceptions in a Django project so I see colorized tracebacks with variable values in development?
Prompt 3
Show me how to activate better-exceptions for a Python script with a single environment variable, without changing any code.
Prompt 4
I'm using better-exceptions in development. What should I do before deploying to production so variable values don't appear in logs?
Open on GitHub → Explain another repo

← qix- on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.