Universal PHP error handling package with enhanced debugging features and LLM-ready output
Crashguard is a framework-agnostic PHP error handling package that automatically adapts to different PHP environments, providing developers with clear, structured, and AI-friendly error output for enhanced debugging workflows.
- ๐ฏ Universal Compatibility - Works across all PHP environments (raw PHP, custom frameworks, etc.)
- ๐จ Beautiful Error Pages - Clean, responsive HTML UI with automatic dark/light mode detection
- ๐ Copy as Markdown - One-click export of error details optimized for LLM analysis
- ๐ฅ๏ธ CLI Support - Colorized terminal output with graceful degradation
- ๐ Security First - Automatic redaction of sensitive data (passwords, keys, tokens)
- ๐ Rich Context - Function arguments, stack traces, request details, and system information
- โก Lightweight - Minimal dependencies, maximum performance
Install via Composer:
composer require aksoyih/crashguard<?php
require_once 'vendor/autoload.php';
use Aksoyih\Crashguard\Crashguard;
// Initialize and register error handlers
$crashguard = Crashguard::getInstance();
$crashguard->register();
// Your application code here...
throw new Exception("Something went wrong!");<?php
use Aksoyih\Crashguard\Crashguard;
$config = [
'auto_detect_theme' => true, // Auto dark/light mode detection
'show_arguments' => true, // Display function arguments
'show_variables' => false, // Show local variables (security risk)
'redact_sensitive' => true, // Redact passwords, keys, etc.
'max_string_length' => 1000, // Truncate long strings
'cli_mode' => null, // Auto-detect CLI environment
];
$crashguard = Crashguard::getInstance($config);
$crashguard->register();- Exception Details: Message, type, HTTP status code (if applicable)
- Precise Location: File path and line number
- Stack Trace: Complete call stack with function arguments
- Request Context: HTTP method, URL, headers, and client information
- System Info: PHP version, memory usage, and performance metrics
- Automatic Theme Detection: Adapts to system dark/light mode preferences
- Responsive Design: Works perfectly on desktop and mobile devices
- Collapsible Sections: Organize information without overwhelming users
- Syntax Highlighting: Code snippets and data structures are beautifully formatted
The "Copy as Markdown" feature generates perfectly formatted error reports for AI analysis:
## Error Summary
- **Message**: Call to undefined method stdClass::someMethod()
- **Type**: `Error`
- **File**: `/path/to/your/file.php`
- **Line**: 42
- **Timestamp**: 2024-01-15 14:30:22
## Stack Trace
### Frame 0
**Function**: `MyClass->processData()`
**Location**: `/path/to/file.php:42`
**Arguments**:
- **[0]** `array`: {"user_id": 123, "email": "[email protected]"}
- **[1]** `string`: "process_action"
- **[2]** `boolean`: true
...Crashguard automatically redacts sensitive information:
- Passwords and passphrases
- API keys and tokens
- Private keys and certificates
- Session data and authentication details
- Any field containing:
password,secret,key,token,auth,private
When running in CLI environments, Crashguard provides colorized terminal output:
php your_script.php๐จ CRASHGUARD ERROR REPORT
============================================================
ERROR SUMMARY
--------------------
Message: Call to undefined method stdClass::someMethod()
Type: Error
File: /path/to/your/script.php
Line: 15
Time: 2024-01-15 14:30:22
STACK TRACE
--------------------
#0 MyClass->processData()
at /path/to/script.php:15
Arguments:
[0] array {"user_id": 123}
[1] string "action"
๐ก Tip: Use Crashguard in web context for enhanced UI and markdown export
Check out the /examples directory for comprehensive usage examples:
basic_usage.php- Simple integration exampleadvanced_usage.php- Advanced configuration and web interfacecli_example.php- Interactive CLI demonstration
-
Basic Example:
php examples/basic_usage.php
-
Web Interface (requires web server):
php -S localhost:8000 -t examples/ # Visit: http://localhost:8000/advanced_usage.php -
CLI Interactive Demo:
php examples/cli_example.php
| Option | Type | Default | Description |
|---|---|---|---|
auto_detect_theme |
bool |
true |
Automatically detect dark/light mode |
show_arguments |
bool |
true |
Display function/method arguments |
show_variables |
bool |
false |
Show local variables (security risk) |
redact_sensitive |
bool |
true |
Redact sensitive data automatically |
max_string_length |
int |
1000 |
Maximum string length before truncation |
cli_mode |
bool|null |
null |
Force CLI mode (null = auto-detect) |
// In your framework's bootstrap or error handler
use Aksoyih\Crashguard\Crashguard;
class AppBootstrap
{
public function initializeErrorHandling()
{
if (app()->environment('local', 'development')) {
Crashguard::getInstance([
'show_arguments' => true,
'show_variables' => false, // Keep false in shared environments
])->register();
}
}
}class ApiException extends Exception
{
private int $statusCode;
public function __construct(string $message, int $statusCode = 500)
{
parent::__construct($message, $statusCode);
$this->statusCode = $statusCode;
}
public function getStatusCode(): int
{
return $this->statusCode;
}
}
// Crashguard will automatically detect and display the HTTP status
throw new ApiException("Resource not found", 404);- Development & Debugging: Enhanced error visibility during development
- API Development: Clear error responses with detailed context
- Legacy Code Modernization: Add modern error handling to existing projects
- AI-Assisted Debugging: Export error details for LLM analysis
- Team Collaboration: Share detailed error reports with team members
- Production Debugging: Safe error reporting without exposing sensitive data
- Logging Integration: Hooks for Monolog, Sentry, and other logging systems
- Custom Themes: User-defined color schemes and layouts
- Error Filtering: Configurable error type filtering and suppression
- Performance Monitoring: Integration with APM tools
- Localization: Multi-language error messages
- Error Analytics: Pattern detection and reporting
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create your 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
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by modern error handling patterns from Laravel, Symfony, and other frameworks
- Built with โค๏ธ for the PHP community
- Special thanks to all contributors and users providing feedback
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: [email protected]
Made with โค๏ธ by aksoyih
Crashguard - Because debugging should be beautiful and intelligent.