Actionable error intelligence for Python — tells you why errors happen and how to fix them.
Project description
failwith
Actionable error intelligence for Python.
When Python tells you what broke, failwith tells you why and how to fix it.
pip install failwith
Quick Start
import failwith
failwith.install()
That's it. Every unhandled exception now gets actionable fix suggestions appended below the standard traceback.
What It Looks Like
Traceback (most recent call last):
File "app.py", line 3, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
┌─ 💡 failwith ─────────────────────────────────────────────────┐
│ │
│ 'cv2' is from the 'opencv-python' package (import ≠ package) │
│ │
│ → Install it: pip install opencv-python │
│ → Or headless: pip install opencv-python-headless │
│ → Active venv: .venv │
│ │
│ 🔍 Python 3.11.5 | venv: .venv | Ubuntu 24.04 │
│ │
└────────────────────────────────────────────────────────────────┘
Features
1. 200+ Import Name → Package Name Mappings
cv2 → opencv-python, PIL → Pillow, sklearn → scikit-learn, yaml → PyYAML, and 200+ more. Never Google "pip install what?" again.
Context-Aware Suggestions
Not pattern matching — actual context analysis. When a ConnectionRefusedError hits on port 5432, failwith knows that's PostgreSQL and suggests the right start command for your OS.
2. Fuzzy Matching for Typos
KeyError, AttributeError, and NameError get fuzzy-matched against available keys, attributes, and names. "Did you mean 'username'?" with edit distance.
3. File System Intelligence
FileNotFoundError shows similar files in the directory, current working directory, and the closest existing parent path. PermissionError shows file ownership and suggests chmod/chown commands.
4. Environment Diagnostics
Every suggestion includes Python version, venv status, and OS — the three things you always need when debugging.
5. Zero Dependencies
Uses only the Python standard library. No rich, no click, nothing. Zero friction to adopt.
6. Never Makes Things Worse
If failwith itself encounters an error, it silently degrades. Your original traceback is always printed first, unmodified.
Supported Error Types (v0.1)
| Error | What failwith adds |
|---|---|
ModuleNotFoundError |
Correct pip install command, import↔package mapping |
ImportError |
Fuzzy name matching, circular import detection |
ConnectionRefusedError |
Service name, start commands, Docker suggestions |
TimeoutError |
Network debugging commands |
ConnectionResetError |
Server-side investigation suggestions |
FileNotFoundError |
Similar files, directory listing, working dir |
PermissionError |
File owner, chmod/chown commands |
KeyError |
Fuzzy match against available keys, .get() suggestion |
AttributeError |
Fuzzy match against attributes, NoneType detection |
NameError |
Scope-aware fuzzy matching, import suggestions |
TypeError |
Type mismatch fixes (str+int, not callable, etc.) |
ValueError |
Conversion fixes, unpacking mismatch |
IndexError |
Collection size context, safe access |
ZeroDivisionError |
Zero-valued variable identification |
UnicodeDecodeError |
Encoding suggestions, chardet recommendation |
UnicodeEncodeError |
Encoding alternatives, error handling modes |
RecursionError |
Recursion limit, call chain, base case reminder |
MemoryError |
Memory optimization strategies |
SyntaxError |
Common fix patterns (missing colon, Python 2→3) |
JSONDecodeError |
Error position context, common JSON issues |
StopIteration |
next() with default, iterator re-creation |
OSError |
Disk space, file descriptor limits, port conflicts |
Advanced Usage
Context Manager
with failwith.catch(reraise=False):
risky_operation()
Decorator
@failwith.catch()
def my_function():
risky_operation()
Custom Suggestions
@failwith.register(MyDatabaseError)
def handle_db_error(exc_type, exc_value, exc_tb, config):
return failwith.Suggestion(
title="Database connection failed",
fixes=[
"Check DATABASE_URL in your .env file",
"Run: docker-compose up -d postgres",
],
)
Configuration
failwith.install(
theme="dark", # "dark" | "light" | "minimal" | "plain"
show_locals=False, # show local variable values
max_suggestions=3, # limit suggestions shown
)
Environment Variables
| Variable | Effect |
|---|---|
NO_COLOR |
Disable colors (standard) |
FAILWITH_NO_COLOR |
Disable colors |
FAILWITH_FORCE_COLOR |
Force colors even in non-TTY |
Contributing
Contributions are welcome! The most impactful way to contribute:
- Add import mappings — edit
src/failwith/data/import_map.py - Improve suggestions — edit handlers in
src/failwith/suggestions/ - Add test cases — real-world error scenarios in
tests/
git clone https://github.com/yashraj/failwith.git
cd failwith
pip install -e ".[dev]"
pytest
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file failwith-0.1.0.tar.gz.
File metadata
- Download URL: failwith-0.1.0.tar.gz
- Upload date:
- Size: 32.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbc7ed081883ce774ae0d648f59b1ad38f07f9efb430116a4d5ef4ef4e6fe27c
|
|
| MD5 |
b3ced7a805030be94e7494c73458978f
|
|
| BLAKE2b-256 |
790a12a0ccdb2182ef1dd0d007adea4837ae2c5a09653af2c4955f85c13df59d
|
Provenance
The following attestation bundles were made for failwith-0.1.0.tar.gz:
Publisher:
publish.yml on Yashraj-Aware/failwith
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
failwith-0.1.0.tar.gz -
Subject digest:
dbc7ed081883ce774ae0d648f59b1ad38f07f9efb430116a4d5ef4ef4e6fe27c - Sigstore transparency entry: 1191596523
- Sigstore integration time:
-
Permalink:
Yashraj-Aware/failwith@ccc37257d8ac15d2890dc66950c9abcde0dca1c1 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Yashraj-Aware
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ccc37257d8ac15d2890dc66950c9abcde0dca1c1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file failwith-0.1.0-py3-none-any.whl.
File metadata
- Download URL: failwith-0.1.0-py3-none-any.whl
- Upload date:
- Size: 31.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f37da8d548594c8134783ac1d0c72d2de75e1a7636276784d78fe6119a736e75
|
|
| MD5 |
0a00d54f60e2ccaeddd90231a5bba3c3
|
|
| BLAKE2b-256 |
df1f571f2c307c062983c6af62ce1062aa175e843fc3d767326f9aa322a1004d
|
Provenance
The following attestation bundles were made for failwith-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on Yashraj-Aware/failwith
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
failwith-0.1.0-py3-none-any.whl -
Subject digest:
f37da8d548594c8134783ac1d0c72d2de75e1a7636276784d78fe6119a736e75 - Sigstore transparency entry: 1191596524
- Sigstore integration time:
-
Permalink:
Yashraj-Aware/failwith@ccc37257d8ac15d2890dc66950c9abcde0dca1c1 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Yashraj-Aware
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ccc37257d8ac15d2890dc66950c9abcde0dca1c1 -
Trigger Event:
release
-
Statement type: