Skip to main content

Friendly explanations for Python errors

Project description

🎯 errfriendly

Friendly, human-readable explanations for Python exceptions.

Python 3.8+ License: MIT PyPI version

errfriendly transforms cryptic Python error messages into clear, actionable explanations. Perfect for beginners learning Python or experienced developers who want faster debugging.


✨ Features

  • 🔍 Clear Explanations: Understand what went wrong in plain English
  • 💡 Actionable Suggestions: Get step-by-step guidance on how to fix common errors
  • 🎯 Zero Dependencies: Pure Python, no external packages required
  • Easy Integration: Just two lines of code to get started
  • 🔧 Configurable: Show or hide the original traceback as needed
  • 📦 18+ Exception Types: Covers all common Python exceptions

📦 Installation

pip install errfriendly

For development installation:

git clone https://github.com/yourusername/errfriendly.git
cd errfriendly
pip install -e ".[dev]"

🚀 Quickstart

import errfriendly

# Enable friendly error messages
errfriendly.install()

# That's it! Now all exceptions will show friendly explanations.

📸 Before & After

Before (Standard Python)

Traceback (most recent call last):
  File "example.py", line 3, in <module>
    result = data[0]
TypeError: 'NoneType' object is not subscriptable

😕 "What does subscriptable even mean?"

After (With errfriendly)

Traceback (most recent call last):
  File "example.py", line 3, in <module>
    result = data[0]
TypeError: 'NoneType' object is not subscriptable

======================================================================
🔍 FRIENDLY ERROR EXPLANATION
======================================================================

📛 TypeError: Trying to index None

💡 What happened:
   You tried to use square brackets [] on a variable that is None.
   This usually happens when a function returned None instead of a list/dict,
   or when a variable wasn't properly initialized.

🔧 How to fix it:
   1. Check if your variable is None before accessing it: `if my_var is not None:`
   2. Make sure the function you called actually returns something.
   3. Print the variable before this line to see what it contains.
   4. Look for functions that might return None on failure (like .get(), .find(), etc.).

======================================================================

Now you know exactly what to do!


🎛️ Configuration

Show Only Friendly Messages (Hide Traceback)

import errfriendly

# Hide the original traceback, show only the friendly explanation
errfriendly.install(show_original_traceback=False)

Disable Friendly Messages

import errfriendly

# Enable friendly messages
errfriendly.install()

# ... your code ...

# Restore original Python behavior
errfriendly.uninstall()

Check Installation Status

from errfriendly.handler import is_installed

if is_installed():
    print("errfriendly is active!")

📋 Supported Exception Types

errfriendly provides friendly explanations for:

Exception Common Causes
TypeError Wrong type operations, None subscripting, not callable
ValueError Invalid conversions, unpacking issues
IndexError List/tuple/string index out of range
KeyError Missing dictionary keys
AttributeError Accessing non-existent attributes
NameError Undefined variables
ImportError Failed imports
ModuleNotFoundError Missing modules
ZeroDivisionError Division by zero
FileNotFoundError Missing files
PermissionError Access denied
RecursionError Infinite recursion
SyntaxError Invalid syntax
UnicodeDecodeError Encoding issues
UnicodeEncodeError Encoding issues
OverflowError Number too large
MemoryError Out of memory
StopIteration Iterator exhausted

Plus a fallback handler for any other exception types!


🛠️ Advanced Usage

Integration with Logging

import errfriendly
import logging

# Install errfriendly
errfriendly.install()

# Your logging still works normally
logging.basicConfig(level=logging.DEBUG)

In Jupyter Notebooks

# Works in Jupyter too!
import errfriendly
errfriendly.install()

# Exceptions in cells will show friendly messages

Testing Your Error Handling

import errfriendly
from errfriendly.messages import get_friendly_message

# Get a friendly message without raising an exception
message = get_friendly_message(TypeError, TypeError("'int' object is not callable"))
print(message)

🧪 Running Tests

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run tests with coverage
pytest --cov=errfriendly --cov-report=html

🗺️ Roadmap

v0.2.0 (Planned)

  • Colored output for terminal
  • Suggestion ranking by likelihood
  • Integration with popular IDEs

v0.3.0 (Future)

  • Machine learning-based error classification
  • Custom error message templates
  • Internationalization (i18n) support
  • Stack trace analysis for better context

v1.0.0 (Goal)

  • Stable API
  • Comprehensive documentation
  • Plugin system for custom handlers
  • Integration with error tracking services (Sentry, etc.)

🤝 Contributing

Contributions are welcome! Here's how you can help:

  1. Report bugs: Open an issue describing the problem
  2. Suggest features: Open an issue with your idea
  3. Submit PRs: Fork, make changes, and submit a pull request

Development Setup

git clone https://github.com/yourusername/errfriendly.git
cd errfriendly
pip install -e ".[dev]"
pytest

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


💖 Acknowledgments

  • Inspired by the Python community's focus on developer experience
  • Thanks to all contributors who help make error messages friendlier

Made with ❤️ for Python developers everywhere

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

errfriendly-0.1.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

errfriendly-0.1.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file errfriendly-0.1.0.tar.gz.

File metadata

  • Download URL: errfriendly-0.1.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for errfriendly-0.1.0.tar.gz
Algorithm Hash digest
SHA256 54338e3c881303dd260593ba624109e88026cc166bfa4c56d7cce64eb6b0f6bb
MD5 a61e4e9365b0052190f7cdf627c748c5
BLAKE2b-256 1ee2e3ae27f846e3995c0bd584e0a86bb5fda3325b7d596106205a9e759d3de2

See more details on using hashes here.

File details

Details for the file errfriendly-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: errfriendly-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for errfriendly-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a3ac2d27aaecb83b2d7b72868a0addf7f196f056c41183a483c2ed51519fe96
MD5 d2dabedce91a46ce9a536cfab2613bbb
BLAKE2b-256 48d34b8d4f4f9fb9c272c92a3cebaae27c9b5620248632bc83857ae427209889

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page