camelot/thrower
Utility wrappers that replace PHP’s inconsistent error/warning/notice behavior with exception-based throwing. Simplifies common tasks by ensuring functions fail predictably via exceptions (excluding deprecation warnings).
file_get_contents, include_once), addressing a common pain point in Laravel/PHP monoliths where mixed error/exception patterns persist. However, its static, opinionated design may clash with Laravel’s dynamic exception-handling ecosystem (e.g., App\Exceptions\Handler, middleware).E_USER_WARNING to HttpResponse for APIs). Compatible with logging drivers (e.g., Monolog, Sentry).debugbar or Sentry also hooks into error handling.Throwable interface). PHP 8.3+ may break due to deprecated functions (e.g., create_function).Artisan commands, Horizon queues).json_decode()) could mask critical errors if not configured to preserve original error codes (e.g., E_USER_ERROR).blackfire.io for high-throughput endpoints (e.g., API rate-limited routes).@include failures) or queue job exceptions?HttpResponseException) for API responses?E_USER_NOTICE) and critical (e.g., E_ERROR) errors for selective wrapping?file_* functions initially)?spatie/laravel-permission) be handled if they emit errors?set_error_handler) that offer more flexibility?422 Unprocessable Entity for E_USER_WARNING).error_log() with structured exceptions for Laravel’s Log::error().trigger_error() → Throwable::error()).whoops or ray for pretty error pages (conflict risk).Illuminate\Support\Facades\* (e.g., Storage, Cache).Illuminate\Foundation\Bootstrap\HandleExceptions).trigger_error() calls (use phpstan rule: error_function_call).E_USER_* errors (e.g., file_get_contents, json_decode).php -l, psalm, or custom regex searches (grep "trigger_error").file_get_contents in a file-upload service).storage/logs/laravel.log before/after).tideways/xhprof).config/thrower.php to toggle wrappers per environment.error_reporting(E_ALL) with Thrower::enable() in bootstrap/app.php.App\Exceptions\Handler to:
public function render($request, Throwable $exception) {
if ($exception instanceof \Camelot\Throwable\ErrorException) {
return response()->json(['error' => $exception->getMessage()], 422);
}
// ... rest of Laravel's logic
}
| Component | Risk Level | Mitigation |
|---|---|---|
| PHP 8.2+ | Medium | Test with PHPUnit on PHP 8.2–8.3. |
| Laravel 9.x+ | Low | Verify Throwable support. |
whoops/ray |
High | Disable conflicting error handlers. |
| Queue Workers | High | Mock Thrower in tests. |
| Blade Templates | High | Avoid wrapping @include directives. |
file_get_contents in app/Console/Commands.Horizon or Laravel Queues.json_decode() with Thrower::json_decode().include_once for config loading.dd(), abort(), or back().App\Exceptions\Handler for global error formatting.try-catch blocks across the codebase.partial mocking in PHPUnit).docs/thrower.md for Laravel use cases.E_USER_WARNING).instanceof \Camelot\Throwable\ErrorException).E_USER_NOTICE wrapped as exceptions may trigger alerts.Throwable wrappers may complicate debugging.ErrorException to add metadata:
class LaravelErrorException extends \Camelot\Throwable\ErrorException {
public function __construct(string $message, int $code, Throwable $previous, array $context = []) {
How can I help you explore Laravel packages today?