Intelligent error handling for Python web applications
Project description
ErrorShield
🛡️ Intelligent error handling for Python web applications
ErrorShield is a comprehensive error handling library that automatically adapts to your environment, providing detailed debugging information in development and secure, user-friendly error pages in production.
✨ Features
- 🔄 Adaptive UI: Automatically switches between detailed development interface and clean production pages
- 📊 Local Dashboard: Real-time error monitoring and debugging dashboard for development
- 🔌 Plugin System: Extensible architecture with built-in plugins for database, memory, and business context
- 🔒 Security First: Automatic PII scrubbing and sensitive data protection
- ⚡ Zero Dependencies: Core functionality works without any external dependencies
- 🎨 Beautiful UI: Neumorphism and glassmorphism design with modern aesthetics
- 📱 Responsive: Mobile-friendly interfaces for all environments
🚀 Quick Start
Installation
pip install error-shield
Basic Usage (Flask)
from flask import Flask
from error_shield import ErrorShield
app = Flask(__name__)
# Initialize ErrorShield - it automatically detects environment
ErrorShield(app)
@app.route('/')
def index():
return 'Hello World!'
@app.route('/error')
def trigger_error():
# This error will be automatically captured and displayed
raise ValueError("This is a test error")
if __name__ == '__main__':
app.run(debug=True)
Advanced Configuration
from error_shield import ErrorShield, ErrorShieldConfig
config = ErrorShieldConfig(
mode='auto', # Auto-detect environment
ui_config={
'company_name': 'My Company',
'primary_color': '#4facfe',
'support_email': 'support@mycompany.com'
},
plugins=['database', 'memory', 'business'],
enable_local_dashboard=True,
dashboard_port=3001
)
ErrorShield(app, config=config)
📖 Documentation
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
mode |
str | 'auto' |
'auto', 'force_prod', or 'force_dev' |
error_context_size |
int | 10 |
Number of errors to keep in memory |
enable_local_dashboard |
bool | True |
Enable development dashboard |
dashboard_port |
int | 3001 |
Port for dashboard server |
sanitize_fields |
list | ['password', 'token', ...] |
Fields to redact from logs |
plugins |
list | [] |
Plugins to enable |
Available Plugins
Database Plugin
Captures SQL queries around errors for debugging.
config = ErrorShieldConfig(
plugins=['database'],
plugins_config={
'database': {
'max_queries': 10
}
}
)
Memory Plugin
Monitors memory usage before and after errors.
config = ErrorShieldConfig(
plugins=['memory'],
plugins_config={
'memory': {
'include_detailed': True
}
}
)
Business Context Plugin
Captures business context for better error understanding.
config = ErrorShieldConfig(
plugins=['business'],
plugins_config={
'business': {
'auto_capture': True,
'context_fields': ['user_id', 'workflow', 'operation']
}
}
)
Manual Error Capture
from error_shield import capture_error, set_business_context
try:
risky_operation()
except Exception as e:
# Set business context
set_business_context({
'user_id': current_user.id,
'workflow': 'payment_processing',
'operation': 'charge_card'
})
# Capture error with additional context
capture_error(e, {
'payment_id': payment.id,
'amount': 99.99
})
raise
Development Dashboard
When running in development mode, ErrorShield automatically starts a local dashboard at http://localhost:3001 where you can:
- View real-time error history
- Filter errors by type, method, or path
- Search through error messages
- View detailed error information
- Clear error history
🎨 UI Examples
Production Error Page
Clean, professional error pages with:
- Company branding
- Error tracking ID
- User-friendly messages
- No technical details exposed
Development Error Page
Rich debugging interface with:
- Full stack traces
- Request details
- Local variables
- System information
- Interactive tabs
🔧 Environment Variables
ErrorShield can be configured via environment variables:
# Dashboard settings
ERRORSHIELD_DASHBOARD_ENABLED=true
ERRORSHIELD_DASHBOARD_PORT=3001
# UI customization
ERRORSHIELD_COMPANY_NAME="My Company"
ERRORSHIELD_PRIMARY_COLOR="#4facfe"
# Security
ERRORSHIELD_MASK_IP=true
🔌 Creating Custom Plugins
from error_shield.plugins import ErrorShieldPlugin
from error_shield.core import ErrorContext
class CustomPlugin(ErrorShieldPlugin):
def __init__(self, config=None):
super().__init__(config)
self.version = "1.0.0"
self.description = "My custom plugin"
def after_capture(self, exception, error_context):
# Add custom information to error context
error_context.additional_context = error_context.additional_context or {}
error_context.additional_context['custom_data'] = "my data"
🛡️ Security Features
- PII Scrubbing: Automatically removes sensitive information
- Rate Limiting: Prevents error logging DoS attacks
- IP Masking: Optional IP address anonymization
- Secure Defaults: Production mode hides all technical details
📊 Framework Support
- ✅ Flask (Primary)
- 🚧 Django (Coming soon)
- 🚧 FastAPI (Coming soon)
- 🚧 Starlette (Coming soon)
🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
📄 License
MIT License - see LICENSE file for details.
🆘 Support
- 📧 Email: support@errorshield.dev
- 📖 Documentation: https://docs.errorshield.dev
- 🐛 Issues: https://github.com/errorshield/errorshield/issues
ErrorShield - Making error handling intelligent, secure, and beautiful. 🛡️
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 error_shield-0.1.0.tar.gz.
File metadata
- Download URL: error_shield-0.1.0.tar.gz
- Upload date:
- Size: 24.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb238c2b534fdbd64ea3abe4ba47c45d7830967d4a59b15c3d77c40ae98e57b9
|
|
| MD5 |
d604099c7c7d76ade062b5018ff8e57c
|
|
| BLAKE2b-256 |
6a3ee6ee99a441038baa7fe6a1983b31d01f0a33314d57f21ac8c81e8223fc8c
|
File details
Details for the file error_shield-0.1.0-py3-none-any.whl.
File metadata
- Download URL: error_shield-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d00d21097ecff86c71fbcdb57809dd91d204faa442f250f2411e8d6f007494d
|
|
| MD5 |
96424a0397fab94cd0572020c3448c53
|
|
| BLAKE2b-256 |
ad424986d006f0c7ac4842b522793fa969159eb1f43eb227feaebb82416bb648
|