A smart CLI tool to analyze error logs from multiple languages and return AI-generated explanations and fix suggestions
Project description
๐งช Error Explainer
AI-powered error analysis and explanation tool for Python developers.
Explain Python error logs using Google's Gemini AI directly from your terminal. Get instant, intelligent explanations and fix suggestions for any Python error.
โจ Features
- ๐ค AI-Powered Explanations: Uses Google Gemini 1.5 Flash for intelligent error analysis
- ๐ Offline Rule-Based Analysis: Works without AI - instant explanations for common errors
- ๐ Multiple Input Methods: Read from files, stdin, or paste interactively
- ๐พ Save & Search: Store explanations and search through your error history
- ๐จ Rich Output: Beautiful terminal formatting with progress indicators
- ๐ Smart Parsing: Intelligent Python traceback and error detection
- ๐ Markdown Export: Export explanations in markdown format
- โก Fast & Lightweight: Quick analysis with minimal dependencies
- ๐ Works Offline: No internet connection required for rule-based mode
๐ Quick Start
Installation
pip install xerror
Setup API Key
- Get your Google Gemini API key from Google AI Studio
- Set the environment variable:
export GOOGLE_API_KEY=your-api-key-here
Or create a .env file in your project directory:
GOOGLE_API_KEY=your-api-key-here
Basic Usage
# Explain error from file (AI mode - requires API key)
xerror error.log
# Explain error offline (no API key required)
xerror error.log --offline
# Paste error interactively
xerror --paste
# Paste error offline
xerror --paste --offline
# Pipe error from stdin
xerror < error.log
# Save explanation to history
xerror error.log --save
# Output in markdown format
xerror error.log --markdown
๐ Python API
The Error Explainer also provides a Python API for programmatic use:
import error_explainer
# Basic usage
result = error_explainer.explain_error("NameError: name 'x' is not defined")
print(result['explanation'])
# Quick explanation (rule-based only)
explanation = error_explainer.quick_explain("TypeError: can only concatenate str (not 'int') to str")
print(explanation)
# Automatic error handling
with error_explainer.auto_explain_exceptions():
undefined_variable # This will be automatically explained
# Function decorator
@error_explainer.explain_function_errors()
def my_function():
return undefined_variable
See API Documentation for complete API reference.
๐ Usage Examples
1. File-based Error Analysis
# Analyze a Python error log file (AI mode)
xerror my_error.log
# Analyze a Python error log file (offline mode)
xerror my_error.log --offline
Example Output (Offline Mode):
๐ Error Summary
NameError: name 'context' is not defined (in views.py:22)
๐ง Explanation
This error occurs when you try to use a variable or function that hasn't been defined or imported.
๐ง Suggested Fixes:
1. Define the variable before using it: `variable_name = value`
2. Import the required module: `from module import function`
3. Check for typos in variable names
4. Ensure the variable is in the correct scope
๐ก Prevention Tips:
1. Always define variables before using them
2. Use meaningful variable names to avoid typos
3. Import required modules at the top of your file
4. Use an IDE with autocomplete to catch undefined variables
2. Interactive Error Pasting
xerror --paste
Then paste your error when prompted.
3. Save Explanations
# Save explanation to ~/.error_explainer_logs/
xerror error.log --save
4. Search Past Explanations
# Search by error type
xerror search "NameError"
# Search by keyword
xerror search "undefined"
# Search by filename
xerror search "views.py"
5. Markdown Export
# Export explanation in markdown format
xerror error.log --markdown
6. Configuration Check
# Check your setup
xerror config-check
๐ง Advanced Usage
AI Mode vs Offline Mode
AI Mode (Default):
- Requires Google Gemini API key
- Provides detailed, contextual explanations
- Best for complex or unique errors
- Requires internet connection
Offline Mode:
- No API key required
- Instant rule-based explanations
- Covers common Python errors
- Works completely offline
# AI mode (requires API key)
xerror error.log
# Offline mode (no API key needed)
xerror error.log --offline
Custom API Key
# Use custom API key for this session
xerror error.log --api-key your-custom-key
Different AI Model
# Use a different Gemini model
xerror error.log --model gemini-1.5-pro
Search with Limits
# Limit search results
xerror search "error" --limit 5
๐ Supported File Formats
.log- Log files.txt- Text files.py- Python files.error- Error files
๐๏ธ Project Structure
xerror/
โโโ xerror/
โ โโโ __init__.py # Package initialization
โ โโโ cli.py # Command line interface
โ โโโ config.py # Configuration management
โ โโโ explainer.py # AI explanation engine
โ โโโ parser.py # Error parsing logic
โ โโโ utils.py # Utility functions
โโโ examples/
โ โโโ error_sample.log # Example error files
โโโ setup.py # Package setup
โโโ requirements.txt # Dependencies
โโโ README.md # This file
๐ฎ Coming Soon
- ๐ฏ Real-time Watch Mode: Monitor running processes for live error detection
- ๐ Background Mode: Daemon-style error monitoring
- ๐ Multi-language Support: JavaScript, TypeScript, C++ error parsing
- ๐ค Multi-model Support: OpenAI, Claude, Ollama integration
- ๐ VSCode Extension: IDE integration
- ๐ฑ Desktop Notifications: Get notified of critical errors
๐ ๏ธ Development
Local Development Setup
# Clone the repository
git clone https://github.com/xerror/xerror.git
cd xerror
# Install in development mode
pip install -e .
# Install development dependencies
pip install -r requirements.txt
Running Tests
# Run tests
pytest
# Run with coverage
pytest --cov=xerror
Building for Distribution
# Build package
python setup.py sdist bdist_wheel
# Install from local build
pip install dist/error_explainer-0.1.0.tar.gz
๐ Requirements
- Python 3.10+
- Google Gemini API key (only for AI mode)
- Internet connection (only for AI mode)
๐ค Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Google Gemini for providing the AI capabilities
- Click for the CLI framework
- Rich for beautiful terminal output
- Python Community for inspiration
๐ Support
- ๐ง Email: contact@xerror.dev
- ๐ Issues: GitHub Issues
- ๐ Documentation: GitHub Wiki
Made with โค๏ธ for Python developers everywhere
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 xerror-0.1.0.tar.gz.
File metadata
- Download URL: xerror-0.1.0.tar.gz
- Upload date:
- Size: 33.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebce427a53e52fc9dcc5be05a7cb7eb77db6464661181426ed9593d51276900a
|
|
| MD5 |
e2aba96981bd7252617fb44052d71339
|
|
| BLAKE2b-256 |
e02a16fa0a810cafe9d1acf3e97a8964d6b2af14c3188f3646422944b4fe9e50
|
File details
Details for the file xerror-0.1.0-py3-none-any.whl.
File metadata
- Download URL: xerror-0.1.0-py3-none-any.whl
- Upload date:
- Size: 35.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7114ec2095bf6a1516fbb64275dae675ca4c9076f47b81a092d03e4f658b833
|
|
| MD5 |
cbbc969c5d545b1c2d3cb7d5205a0f88
|
|
| BLAKE2b-256 |
a35e1da0a341c1009ff1c9492f2c964aa26c9768fa24750c6b7792cf03b98721
|