Thanks to visit codestin.com
Credit goes to github.com

Skip to content

aksoyih/crashguard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿšจ Crashguard

Universal PHP error handling package with enhanced debugging features and LLM-ready output

PHP Version License

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.

โœจ Features

  • ๐ŸŽฏ 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

๐Ÿš€ Installation

Install via Composer:

composer require aksoyih/crashguard

๐Ÿ“– Quick Start

Basic Usage

<?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!");

Advanced Configuration

<?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();

๐ŸŽฏ What Makes Crashguard Special?

๐Ÿ” Enhanced Error Information

  • 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

๐ŸŽจ Intelligent UI

  • 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

๐Ÿ“‹ LLM Integration

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

...

๐Ÿ›ก๏ธ Security Features

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

๐Ÿ–ฅ๏ธ CLI Support

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

๐Ÿ“‚ Examples

Check out the /examples directory for comprehensive usage examples:

  • basic_usage.php - Simple integration example
  • advanced_usage.php - Advanced configuration and web interface
  • cli_example.php - Interactive CLI demonstration

Running Examples

  1. Basic Example:

    php examples/basic_usage.php
  2. Web Interface (requires web server):

    php -S localhost:8000 -t examples/
    # Visit: http://localhost:8000/advanced_usage.php
  3. CLI Interactive Demo:

    php examples/cli_example.php

โš™๏ธ Configuration Options

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)

๐Ÿ”ง Integration Patterns

Framework Integration

// 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();
        }
    }
}

Custom Exception Integration

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);

๐ŸŽฏ Use Cases

  • 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

๐Ÿ”ฎ Roadmap

  • 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

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

  1. Fork the repository
  2. Create your 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

  • 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

๐Ÿ“ž Support


Made with โค๏ธ by aksoyih

Crashguard - Because debugging should be beautiful and intelligent.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages