isaidgitmenow / laravel-errors
Enterprise-grade, highly configurable error handling for Laravel 13.
Requires
- php: ^8.4
- illuminate/contracts: ^11.0|^12.0|^13.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.9
- orchestra/testbench: ^9.0|^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
- phpunit/phpunit: ^11.0|^12.0|^13.0
Suggests
- barryvdh/laravel-debugbar: Required for Debugbar integration.
- filament/filament: Required for Filament panel integration.
- inertiajs/inertia-laravel: Required for Inertia.js integration.
- livewire/livewire: Required for Livewire component integration.
- sentry/sentry-laravel: Required for Sentry integration.
- spatie/laravel-ignition: Required for Ignition debug mode integration.
README
composer require isaidgitmenow/laravel-errors
A powerful, elegant, and declarative error handling package for modern Laravel applications (Laravel 11+).
Built with PHP 8.4+ Attributes and strictly adhering to SOLID principles, this package replaces traditional, boilerplate-heavy exception rendering and reporting methods with clean, declarative attributes directly on your Exception classes.
โจ Features
- Declarative PHP 8 Attributes: Configure HTTP codes, reporting rules, rate limiting, and context directly on your exception classes.
- Plug-and-Play Frontend Integrations: Automatically detects the context of the request (Filament, Livewire, Inertia, API, Web) and formats the response appropriately so your SPA or Admin panel doesn't break on a 500 error.
- Bulletproof Resilience: Includes a self-healing
try/catchwrapper so an error in your error handler never causes a White Screen of Death (WSOD). - Deep Attribute Inspection: Safely traverses Laravel's wrapped exceptions (e.g.,
QueryException,ViewException) to find and apply your custom attributes on the original exception. - Spatie Ignition & Laravel Debugbar Ready: Seamlessly integrates with local developer tools without breaking production flows.
- Xdebug IDE Enrichment: Push sanitized
#[WithContext]payloads directly to your IDE as debug notifications. - Auto-Injection into Laravel Context: Automatically forwards
#[WithContext]data to downstream trackers like Sentry or Flare via Laravel 11's globalContext. - Data Sanitization: Built-in redaction for sensitive keys (like passwords and API tokens) before they hit logs or external trackers.
- Anti-Spam Rate Limiting: Prevent cascading failures from exhausting your error tracker quotas using the
#[RateLimit]attribute. - Octane Compatible: Automatically flushes the reflection cache and dynamic state after every request under Swoole / RoadRunner to prevent memory leaks.
- Dynamic Pass-Through: Third-party packages can register exceptions to bypass the pipeline at runtime โ no config edits required.
- Fallback Logging: Ensures your application never runs completely blind by falling back to Laravel's default logger if no reporters are configured โ whether via config or dynamically via
addReporter(). - Environment-Specific Reporting: Restrict
#[ReportTo]to specific environments (e.g., only send Slack alerts inproduction). make:errorArtisan Command: Scaffold fully decorated exception classes in seconds withphp artisan make:error.- Static Analysis Ready: Ships with a
phpstan.neon.distpre-configured for Larastan level 5. - MCP Server Built-in: Includes a native Model Context Protocol (MCP) server so your AI agent can create, inspect, and simulate errors straight from your IDE.
- CI/CD Ready: Includes a GitHub Actions workflow matrix covering PHP 8.4/8.5 ร Laravel 11/12.
๐ฆ Requirements
- PHP 8.4+
- Laravel 11.0+
๐ Installation & Setup
You can install the package via composer:
composer require isaidgitmenow/laravel-errors
Optionally, publish the configuration file to customize the pipeline:
php artisan vendor:publish --tag="laravel-errors-config"
Integration is incredibly simple. Open your bootstrap/app.php and register the handler:
// bootstrap/app.php use Illuminate\Foundation\Configuration\Exceptions; use Isaidgitmenow\LaravelErrors\ErrorHandler; return Application::configure(basePath: dirname(__DIR__)) // ... ->withExceptions(function (Exceptions $exceptions) { // Let the package orchestrate your entire error pipeline: ErrorHandler::handle($exceptions); })->create();
๐ Documentation
For detailed usage and advanced configuration, please refer to the specific documentation chapters:
Core Architecture And Api
- ๐๏ธ Core Architecture & API Reference
- ๐ต๏ธโโ๏ธ How Does It Know the Request Context?
- ๐ The Complete Lifecycle: Generating, Throwing & Logging
Usage And Attributes
- ๐ Usage: The Attributes API
- ๐ก The Ultimate Exception Example
- ๐ค Do I Still Need
try/catch?
Renderers
- ๐จ Context Detectors & Renderers
- ๐ Web Renderer Example
- ๐ก API Renderer Example
- โก Livewire Renderer Example
- ๐ก๏ธ Filament Renderer Example
- โ๏ธ Inertia.js Renderer Example
Reporters And Integrations
- ๐ข Reporters
- ๐ฌ Slack Integration Example
- ๐ฆ NightWatch Integration Example
- ๐ฅ Flare (or Sentry) Integration
- ๐ Laravel Debugbar Integration Example
- ๐ Xdebug IDE Enrichment
- ๐ Routing to Different Log Channels
- ๐ Environment-Specific Reporting
Exception Handling Mechanics
- ๐ง Bypassing the Pipeline: Native Laravel Exceptions
- ๐ฆ The "Pass Through" Exceptions (Complete List)
- ๐คทโโ๏ธ Handling Generic (Un-decorated) Exceptions
- ๐ A Note on API Form Requests (
ValidationException) - ๐ก๏ธ Working with Gates & Permissions (
AuthorizationException) - ๐ Translated Error Messages Example
Advanced Configuration And Patterns
- โ๏ธ Advanced Configuration & Mechanics
- ๐งฉ Custom Detectors, Renderers, and Reporters
- ๐๏ธ Building a Custom Detector (Step-by-Step)
- ๐ Anti-Spam: Error Rate Limiting (In-Depth)
- โก Performance & Error Cache (Octane / Testing)
- ๐คฏ Exotic Use Cases & Advanced Patterns
- ๐ Advanced API: Complying with JSON:API Specification
Ecosystem And Commands
- โ๏ธ Queue Jobs Integration
- ๐ป Artisan Commands Integration
- ๐ ๏ธ Generating Exceptions:
make:error - ๐๏ธ Domain Driven Design (DDD) Support
Testing And Ci
- ๐งช Testing Your Application
- ๐ฌ Static Analysis with Larastan
- ๐ค Continuous Integration (GitHub Actions)
๐ค AI Agent Integration (MCP Server)
This package ships with a native Model Context Protocol (MCP) server, meaning your favorite AI coding assistant (like Claude Desktop, Cursor, or Antigravity) can connect directly to your local error pipeline.
With the MCP integration enabled, your AI can:
- Generate Exceptions: Ask your AI to "Create a
PaymentFailederror with a 402 status that reports to Slack", and it will use the MCP tool to generate the fully decorated file. - Inspect Pipeline: The AI can query your active Detectors, Renderers, and Reporters.
- Search Logs: The AI can query your application's historical JSONL error logs directly to help you debug past errors.
- Simulate Errors: The AI can instantiate and run exceptions through the pipeline in a rolled-back transaction to verify how they behave.
Setup
To connect your AI agent, add the following configuration to your client's mcp_config.json (or claude_desktop_config.json):
{
"mcpServers": {
"laravel-errors-mcp": {
"command": "cmd",
"args": [
"/c",
"cd /path/to/your/project && php artisan errors:mcp"
]
}
}
}
(If you are on Linux or macOS, simply use bash and -c instead of cmd and /c)
๐งช Testing
The package includes a comprehensive test suite (built with Pest and Orchestra Testbench).
composer test
Run static analysis with Larastan:
composer phpstan
๐ License
This package is Dual Licensed:
- Open Source (GPLv3): Free for personal or open-source projects. If you use this package, your application must also be open-source under the GPLv3.
- Commercial Use: If you are building a commercial, proprietary, or closed-source application, you must purchase a Commercial License.
Purchase a License
To purchase a Commercial License, please visit unicweb.ro or contact lucian.laravel@gmail.com for inquiries.
Please read the full LICENSE Agreement for complete details.