yiisoft/friendly-exception
Defines FriendlyExceptionInterface for exceptions that provide a human-friendly name and suggested solution. Lets error handlers detect these exceptions and display clearer, actionable information on error pages. Includes guidance for writing short, markdown-based solutions.
App\Exceptions\Handler can still integrate seamlessly, though PHP 7.4’s deprecations (e.g., create_function) may require minor adjustments in legacy Laravel apps..env) remain unaffected, but PHP 7.4’s stricter type hints may necessitate explicit type declarations in Laravel’s exception handlers.@Middleware(FriendlyExceptionMiddleware::class)).illuminate\pipeline) may require testing for edge cases.array_unpack changes) could introduce subtle bugs.HttpFoundation) may have version constraints; Laravel’s symfony/http-foundation (v6.x) is likely compatible but should be validated.xdebug or Blackfire.Illuminate\Support\Collection methods) that might conflict with PHP 8.5’s stricter type system?create_function) break Laravel’s legacy exception handlers if integrated with this package?array_is_list) for tighter integration?platform-check in composer.json)?App\Exceptions\Handler::render() with PHP 8.5’s typed properties (e.g., public function render($request, Throwable $exception): Response) for type safety.// Laravel 11+
#[Middleware(FriendlyExceptionMiddleware::class)]
public function showErrorPage() { ... }
Renderer to Laravel’s container with explicit PHP version constraints:
$this->app->bind(Renderer::class, function ($app) {
return new Renderer($app['config']['app.env'] === 'production');
});
composer.json to PHP 8.1+ (required for Laravel 10/11) and test the package.composer why-not to identify dependency conflicts with PHP 8.5.Handler::render() with the package’s Renderer in a feature branch.APP_DEBUG=true and PHP 8.5’s JIT enabled (php.ini).Renderer to use Laravel’s HttpResponse or JsonResponse for API errors.@foreach).Illuminate package versions (e.g., illuminate/support v9.x+).whoops (error pages): May duplicate functionality; configure exclusivity.laravel-debugbar: Ensure stack traces align between tools.php -d opcache.jit_buffer_size=100M to simulate JIT impact./health).try-catch in middleware to fall back to Laravel’s default handler if the package fails.yiisoft/friendly-exception to ^1.2 in composer.json to avoid PHP 8.5+ breaking changes.composer why to audit Symfony component versions (e.g., symfony/http-foundation).README.md and CI templates (e.g., GitHub Actions)..env:
FRIENDLY_EXCEPTION_PHP_VERSION=8.5
FRIENDLY_EXCEPTION_CACHE_DRIVER=file
app/Exceptions/FriendlyRenderer.php extension for Laravel-specific logic (e.g., route debugging).TypeError for undefined array offsets).FriendlyExceptionRenderer events with context:
Sentry\configureScope(function ($scope) {
$scope->setExtra('exception_renderer', 'friendly');
});
file or redis cache:
Cache::remember('error_500', 3600, fn() => $renderer->render($exception));
php -d xdebug.mode=profile to identify bottlenecks.return response()->json(['error' => $renderer->getMessage()], 500);
config('app.env') to switch renderers:
$renderer = config('app.env') === 'production'
? new ProdRenderer()
: new DevRenderer();
try {
return $renderer->render($exception);
} catch (Throwable $e) {
return new Response("Error rendering exception", 500);
}
$renderer->setSensitiveDataFilter(fn($data) => str_replace(base_path(), '[path]', $data));
php artisan view:clear and test edge cases (e.g., empty exception messages).How can I help you explore Laravel packages today?