A smart CLI tool to analyze error logs from multiple languages and return AI-generated explanations and fix suggestions
Project description
๐งช Error Explainer
Author: Avishek Devnath
Email: avishekdevnath@gmail.com
AI-powered error analysis and explanation tool for multiple programming languages.
Explain error logs from Python, JavaScript, TypeScript, C++, and Java using Google's Gemini AI directly from your terminal. Get instant, intelligent explanations and fix suggestions for any programming error.
Built with โค๏ธ by Avishek Devnath
โจ 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
- ๐ Multi-Language Support: Python, JavaScript, TypeScript, C++, Java
- ๐ 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 traceback and error detection across languages
- ๐ Markdown Export: Export explanations in markdown format
- โก Fast & Lightweight: Quick analysis with minimal dependencies
- ๐ Works Offline: No internet connection required for rule-based mode
- ๐ Real-time Monitoring: Watch running processes for live error detection
- ๐ Python API: Programmatic access for integration with your tools
- ๐ง Multi-Model Support: Switch between different AI providers
- ๐ฏ Language Auto-Detection: Automatically identifies programming language from error logs
๐ Quick Start
Installation
For Users:
pip install xerror
For Developers:
# Clone the repository
git clone https://github.com/xerror/xerror.git
cd xerror
# Install in development mode
pip install -e .
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
๐ Supported Languages
| Language | Error Detection | AI Explanation | Rule-Based | Examples | Status |
|---|---|---|---|---|---|
| Python | โ | โ | โ | NameError, TypeError, ImportError | ๐ข Production Ready |
| JavaScript | โ | โ | โ | TypeError, ReferenceError, SyntaxError | ๐ข Production Ready |
| TypeScript | โ | โ | โ | TS2322, TS2339, TS2307 | ๐ข Production Ready |
| C++ | โ | โ | โ | Compilation errors, runtime errors | ๐ข Production Ready |
| Java | โ | โ | โ | NullPointerException, ClassNotFoundException | ๐ข Production Ready |
๐ Usage Examples
1. Multi-Language Error Analysis
# Python error
xerror python_error.log
# JavaScript error
xerror javascript_error.log
# TypeScript error
xerror typescript_error.log
# C++ error
xerror cpp_error.log
# Java error
xerror java_error.log
2. Language Detection
# Auto-detect language from error
xerror detect "NameError: name 'x' is not defined"
xerror detect "TypeError: Cannot read property 'length' of undefined"
xerror detect "TS2322: Type 'string' is not assignable to type 'number'"
xerror detect "error: 'cout' was not declared in this scope"
xerror detect "Exception in thread \"main\" java.lang.NullPointerException"
3. Real-time Process Monitoring
# Watch a running process for errors
xerror watch "python my_script.py"
# Watch with custom command
xerror watch "npm start"
# Watch in background mode
xerror watch "python long_running_script.py" --background
4. Python API Examples
import xerror
# Basic error explanation
result = xerror.explain_error("NameError: name 'x' is not defined")
print(result['explanation'])
# Language detection
language = xerror.detect_language("TypeError: Cannot read property 'length' of undefined")
print(f"Detected language: {language}")
# Parse error details
error_info = xerror.parse_error("TS2322: Type 'string' is not assignable to type 'number'")
print(f"Error type: {error_info.error_type}")
print(f"Language: {error_info.language}")
# Quick explanation (rule-based only)
explanation = xerror.quick_explain("TypeError: can only concatenate str (not 'int') to str")
print(explanation)
# Automatic error handling
with xerror.auto_explain_exceptions():
undefined_variable # This will be automatically explained
# Function decorator
@xerror.explain_function_errors()
def my_function():
return undefined_variable
5. Error Examples by Language
Python Errors
# NameError
NameError: name 'x' is not defined
# TypeError
TypeError: can only concatenate str (not 'int') to str
# ImportError
ImportError: No module named 'requests'
# IndentationError
IndentationError: expected an indented block
# AttributeError
AttributeError: 'list' object has no attribute 'append'
# ValueError
ValueError: invalid literal for int() with base 10: 'abc'
JavaScript Errors
// TypeError
TypeError: Cannot read property 'length' of undefined
// ReferenceError
ReferenceError: x is not defined
// SyntaxError
SyntaxError: Unexpected token '{'
// RangeError
RangeError: Maximum call stack size exceeded
// URIError
URIError: URI malformed
TypeScript Errors
// TS2322: Type assignment error
TS2322: Type 'string' is not assignable to type 'number'
// TS2339: Property does not exist
TS2339: Property 'length' does not exist on type 'number'
// TS2307: Module not found
TS2307: Cannot find module './Component'
// TS2345: Argument type mismatch
TS2345: Argument of type 'string' is not assignable to parameter of type 'number'
// TS2531: Object is possibly null
TS2531: Object is possibly 'null'
C++ Errors
// Compilation error
error: 'cout' was not declared in this scope
// Syntax error
error: expected ';' before '}' token
// Missing include
error: 'vector' was not declared in this scope
// Linker error
undefined reference to 'main'
// Runtime error
Segmentation fault (core dumped)
Java Errors
// NullPointerException
Exception in thread "main" java.lang.NullPointerException
// Compilation error
error: cannot find symbol: variable x
// Class not found
java.lang.ClassNotFoundException: com.example.MyClass
// ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 3
// NumberFormatException
java.lang.NumberFormatException: For input string: "abc"
๐ Python API Reference
Core Functions
| Function | Description | Returns | Example |
|---|---|---|---|
explain_error(error_text) |
Full AI-powered error explanation | Dict with explanation, confidence, method | explain_error("NameError: name 'x' is not defined") |
quick_explain(error_text) |
Fast rule-based explanation | String explanation | quick_explain("TypeError: can only concatenate str (not 'int') to str") |
detect_language(error_text) |
Detect programming language | Language enum | detect_language("TypeError: Cannot read property 'length' of undefined") |
parse_error(error_text) |
Parse error details | ErrorInfo object | parse_error("TS2322: Type 'string' is not assignable to type 'number'") |
get_supported_languages() |
Get list of supported languages | List of Language enums | get_supported_languages() |
Context Managers
| Context Manager | Description | Example |
|---|---|---|
auto_explain_exceptions() |
Automatically explain any exceptions | with auto_explain_exceptions(): ... |
watch_process(command) |
Monitor a running process for errors | with watch_process("python script.py"): ... |
Decorators
| Decorator | Description | Example |
|---|---|---|
explain_function_errors() |
Automatically explain errors in decorated function | @explain_function_errors() |
See API Documentation for complete API reference.
๐งช Testing
Running Tests
# Run all tests
python -m pytest
# Run specific test categories
python -m pytest test_multi_language.py
python -m pytest test_api_proper.py
python -m pytest test_watcher.py
python -m pytest test_multi_model.py
# Run with coverage
python -m pytest --cov=xerror
# Run with verbose output
python -m pytest -v
# Run tests in parallel
python -m pytest -n auto
Test Coverage
| Component | Test Files | Coverage | Status |
|---|---|---|---|
| Core Language Detection | test_multi_language.py |
โ 100% | ๐ข Complete |
| Python API | test_api_proper.py |
โ 100% | ๐ข Complete |
| Real-time Monitoring | test_watcher.py |
โ 100% | ๐ข Complete |
| Multi-Model Support | test_multi_model.py |
โ 100% | ๐ข Complete |
| Error Parsing | test_parser.py |
โ 100% | ๐ข Complete |
| Rule-Based Explainer | test_rule_based.py |
โ 100% | ๐ข Complete |
Test Examples
# Test language detection
python test_multi_language.py
# Test API functionality
python test_api_proper.py
# Test watcher functionality
python test_watcher.py
# Test multi-model support
python test_multi_model.py
๐ง Advanced Usage
AI Mode vs Offline Mode
| Feature | AI Mode | Offline Mode |
|---|---|---|
| API Key Required | โ Yes | โ No |
| Internet Connection | โ Yes | โ No |
| Response Time | 2-5 seconds | Instant |
| Explanation Quality | High (contextual) | Good (rule-based) |
| Coverage | All errors | Common errors |
| Cost | API usage | Free |
| Best For | Complex/unique errors | Common errors, offline use |
# AI mode (requires API key)
xerror error.log
# Offline mode (no API key needed)
xerror error.log --offline
Multi-Model Support
| Model | Provider | Status | Features | Cost |
|---|---|---|---|---|
| Gemini 1.5 Flash | โ Active | Fast, cost-effective | Low | |
| Gemini 1.5 Pro | โ ๏ธ Limited | Higher quality, slower | Medium | |
| OpenAI GPT-4 | OpenAI | ๐ง Optional | High quality, paid | High |
| Ollama Local | Local | ๐ง Optional | Offline, customizable | Free |
Custom Configuration
# Use custom API key for this session
xerror error.log --api-key your-custom-key
# Use different AI model
xerror error.log --model gemini-1.5-pro
# Set custom log directory
export ERROR_EXPLAINER_LOG_DIR=/custom/path
xerror error.log --save
# Set default model
export DEFAULT_MODEL=gemini-1.5-flash
Search with Filters
# Search by error type
xerror search "NameError"
# Search by language
xerror search "python"
# Search by keyword
xerror search "undefined"
# Search by filename
xerror search "views.py"
# Limit search results
xerror search "error" --limit 5
# Search with date range
xerror search "error" --since "2024-01-01" --until "2024-12-31"
๐จ Troubleshooting
Common Issues
| Issue | Solution | Status |
|---|---|---|
| API Key Error | Set GOOGLE_API_KEY environment variable |
โ Fixed |
| Language Not Detected | Use --offline mode or check error format |
โ Fixed |
| Slow Response | Use offline mode or check internet connection | โ Fixed |
| Import Error | Install with pip install xerror |
โ Fixed |
| Permission Denied | Check file permissions or use --offline |
โ Fixed |
Error Messages
# If you see: "No API key found"
export GOOGLE_API_KEY=your-api-key-here
# If you see: "Language not detected"
xerror error.log --offline
# If you see: "Import error"
pip install --upgrade xerror
# If you see: "Permission denied"
chmod +r error.log
Performance Tips
- Use
--offlinemode for faster responses - Save explanations with
--saveto avoid re-analyzing - Use specific error messages rather than full logs
- Set up your API key in
.envfile for convenience
๐ Supported File Formats
| Format | Extension | Description | Example |
|---|---|---|---|
| Log files | .log |
Standard log files | error.log |
| Text files | .txt |
Plain text files | error.txt |
| Python files | .py |
Python source files | script.py |
| Error files | .error |
Dedicated error files | error.error |
| Any text | * |
Any text-based file | output |
๐๏ธ 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
โ โโโ rule_based_explainer.py # Offline rule-based analysis
โ โโโ api.py # Python API functions
โ โโโ watcher.py # Real-time process monitoring
โ โโโ models.py # Multi-model support
โ โโโ language_parsers.py # Multi-language parsing
โ โโโ utils.py # Utility functions
โโโ examples/
โ โโโ error_sample.log # Python error example
โ โโโ javascript_error.log # JavaScript error example
โ โโโ typescript_error.log # TypeScript error example
โ โโโ cpp_error.log # C++ error example
โ โโโ java_error.log # Java error example
โ โโโ api_usage_examples.py # API usage examples
โโโ setup.py # Package setup
โโโ requirements.txt # Dependencies
โโโ env.example # Environment template
โโโ README.md # This file
โโโ API_DOCUMENTATION.md # API documentation
๐ฎ Roadmap
| Feature | Status | Priority | ETA | Description |
|---|---|---|---|---|
| VSCode Extension | ๐ง In Progress | High | Q4 2024 | IDE integration with real-time error detection |
| GitHub Actions CI | ๐ง In Progress | Medium | Q4 2024 | Automated testing and deployment |
| Desktop Notifications | ๐ Planned | Medium | Q1 2025 | Get notified of critical errors |
| More Languages (Go, Rust) | ๐ Planned | Low | Q2 2025 | Extended language support |
| Web Interface | ๐ Planned | Low | Q3 2025 | Browser-based error analysis |
| Mobile App | ๐ Planned | Low | Q4 2025 | iOS/Android error analysis |
๐ ๏ธ 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
# Set up environment
cp env.example .env
# Edit .env with your API keys
Development Commands
# Run tests
python -m pytest
# Run linting
flake8 xerror/
# Format code
black xerror/
# Type checking
mypy xerror/
# Build package
python setup.py sdist bdist_wheel
# Install from local build
pip install dist/xerror-0.1.0.tar.gz
# Run security checks
bandit -r xerror/
Contributing Guidelines
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Run tests:
python -m pytest - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ Requirements
| Component | Version | Required | Notes |
|---|---|---|---|
| Python | 3.10+ | โ Yes | Core requirement |
| Google Gemini API | Latest | โ ๏ธ For AI mode | Free tier available |
| Internet Connection | - | โ ๏ธ For AI mode | Not needed for offline mode |
| Click | 8.1.0+ | โ Yes | CLI framework |
| Rich | 13.0.0+ | โ Yes | Terminal formatting |
๐ค Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
Development Areas
| Area | Description | Priority | Status |
|---|---|---|---|
| Language Support | Add new programming languages | High | ๐ง In Progress |
| Error Patterns | Improve error detection patterns | High | ๐ง In Progress |
| AI Models | Add support for new AI providers | Medium | ๐ Planned |
| Performance | Optimize parsing and analysis speed | Medium | ๐ Planned |
| Documentation | Improve docs and examples | Low | โ Complete |
How to Contribute
- Report Bugs: Use GitHub Issues
- Request Features: Use GitHub Discussions
- Submit Code: Follow the contributing guidelines above
- Improve Docs: Submit PRs for documentation improvements
๐ 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
- All contributors and users who provided feedback
๐จโ๐ป Author
Avishek Devnath
- ๐ง Email: avishekdevnath@gmail.com
- ๐ GitHub: @avishekdevnath
- ๐ผ LinkedIn: Avishek Devnath
๐ Support
| Channel | Link | Response Time | Best For |
|---|---|---|---|
| ๐ง Email | avishekdevnath@gmail.com | 24-48 hours | Personal support, feature requests |
| ๐ Issues | GitHub Issues | 1-3 days | Bug reports, technical issues |
| ๐ Documentation | GitHub Wiki | Instant | How-to guides, tutorials |
| ๐ฌ Discussions | GitHub Discussions | 1-2 days | General questions, community help |
Made with โค๏ธ by Avishek Devnath for 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-1.0.0.tar.gz.
File metadata
- Download URL: xerror-1.0.0.tar.gz
- Upload date:
- Size: 40.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
357b0de72bf175a38bf48cfea4738a7bd2d83ba449350d633bc64e64e8e05834
|
|
| MD5 |
1d9c323ea3024040fad369e8756c1d7d
|
|
| BLAKE2b-256 |
5a31afa046295aed1ef1555d804416b7d228ceef954018b98c841cbdd977cec9
|
File details
Details for the file xerror-1.0.0-py3-none-any.whl.
File metadata
- Download URL: xerror-1.0.0-py3-none-any.whl
- Upload date:
- Size: 38.6 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 |
abc65a37fb2624ef4dc679167fb101292cfaa0899b285c3b1393dc2e8c3d35f6
|
|
| MD5 |
3f2c34dc40913f7854c179f0c6c3775a
|
|
| BLAKE2b-256 |
a18edbdbd268b6f078a2bda04f0b1fc3d75447e4e340cf23b274e4f0574a4bf4
|