Skip to main content

A smart CLI tool to analyze error logs from multiple languages and return AI-generated explanations and fix suggestions

Project description

๐Ÿงช Error Explainer

Python 3.10+ License: MIT PyPI

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

  1. Get your Google Gemini API key from Google AI Studio
  2. 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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

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

๐Ÿ™ Acknowledgments

๐Ÿ“ž Support


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

xerror-0.1.0.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

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

xerror-0.1.0-py3-none-any.whl (35.3 kB view details)

Uploaded Python 3

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

Hashes for xerror-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ebce427a53e52fc9dcc5be05a7cb7eb77db6464661181426ed9593d51276900a
MD5 e2aba96981bd7252617fb44052d71339
BLAKE2b-256 e02a16fa0a810cafe9d1acf3e97a8964d6b2af14c3188f3646422944b4fe9e50

See more details on using hashes here.

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

Hashes for xerror-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f7114ec2095bf6a1516fbb64275dae675ca4c9076f47b81a092d03e4f658b833
MD5 cbbc969c5d545b1c2d3cb7d5205a0f88
BLAKE2b-256 a35e1da0a341c1009ff1c9492f2c964aa26c9768fa24750c6b7792cf03b98721

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