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
  • 🎨 Colorful Output: ANSI colors in terminal for better readability
  • 📝 Logging Support: Optionally log exceptions to a file
  • 🎯 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
  • 📦 23 Exception Types: Covers all common Python exceptions

📦 Installation

pip install errfriendly

For development installation:

git clone https://github.com/infinawaz/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!")

Enable Logging to File

import errfriendly

# Log exceptions to a file for later review
errfriendly.install(log_file="errors.log")

📋 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
AssertionError Failed assertions
NotImplementedError Unimplemented features
KeyboardInterrupt User interruption (Ctrl+C)
TimeoutError Operation timeouts
ConnectionError Network connection failures

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 ✅ (Current)

  • Colored output for terminal (ANSI colors)
  • Logging exceptions to file
  • Additional exception handlers (5 new types)
  • Graceful failure handling

v0.3.0 (Planned)

  • Suggestion ranking by likelihood
  • Integration with popular IDEs
  • Custom error message templates
  • 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.)
  • Internationalization (i18n) support

🤝 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/infinawaz/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.2.0.tar.gz (21.7 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.2.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for errfriendly-0.2.0.tar.gz
Algorithm Hash digest
SHA256 809f8a278eae61d3a721bf9a340be6cee076c647f8f593f5d2182770e7222c24
MD5 b034676f61a63c2903e79be1629751a7
BLAKE2b-256 c3ca7cb712e159f05735b9753c66104a4766b878bfecd6d2d444be2ac9ca501f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: errfriendly-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b30601cf7f9a0584b7ee0ec6f244a02b992d7ca48a9731269da0e510ff5eb04
MD5 6dbff8971a088f2a4354cde3a825e8e1
BLAKE2b-256 ebd547d203bd815b526915894c80aa496402e29f601aa9fba528a7ba91e159f4

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