Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Friendly Exception Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel Compatibility: The package remains framework-agnostic but now explicitly supports PHP 7.4–8.5, aligning with Laravel’s current LTS (10.x/11.x) and PHP 8.1+ requirements. Laravel’s 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.
  • Modularity: The package’s renderer/handler separation is unchanged, maintaining compatibility with Laravel’s service container and middleware stack. PHP 8.5’s new features (e.g., typed properties) could enable future optimizations.
  • Separation of Concerns: Environment-based configurations (e.g., .env) remain unaffected, but PHP 7.4’s stricter type hints may necessitate explicit type declarations in Laravel’s exception handlers.

Integration Feasibility

  • Low-Coupling Design: The PSR-15 middleware approach is still viable, but PHP 8.5’s attribute-based middleware (Laravel 11+) may offer cleaner integration paths (e.g., @Middleware(FriendlyExceptionMiddleware::class)).
  • PSR-15 Middleware Support: No changes to the package’s middleware interface, but Laravel’s evolving middleware stack (e.g., illuminate\pipeline) may require testing for edge cases.
  • Template Flexibility: Blade templates remain compatible, though PHP 8.5’s JIT compiler could impact rendering performance—benchmarking recommended.

Technical Risk

  • PHP Version Gaps:
    • Laravel 9.x (PHP 8.0): Fully supported, but PHP 7.4’s removal may force upgrades.
    • Laravel 10.x/11.x (PHP 8.1+): Optimal compatibility, but PHP 8.5’s new features (e.g., array_unpack changes) could introduce subtle bugs.
  • Dependency Conflicts: Symfony components (e.g., HttpFoundation) may have version constraints; Laravel’s symfony/http-foundation (v6.x) is likely compatible but should be validated.
  • Performance Overhead: PHP 8.5’s JIT could improve or degrade performance depending on error-page complexity; profile with xdebug or Blackfire.

Key Questions

  1. PHP 8.5 Readiness: Are there Laravel-specific edge cases (e.g., Illuminate\Support\Collection methods) that might conflict with PHP 8.5’s stricter type system?
  2. Deprecation Impact: Will PHP 7.4’s removed functions (e.g., create_function) break Laravel’s legacy exception handlers if integrated with this package?
  3. Laravel 11+ Features: Can the package leverage Laravel 11’s new middleware attributes or other PHP 8.5 features (e.g., array_is_list) for tighter integration?
  4. Backward Compatibility: How does this version handle Laravel apps still on PHP 7.4 (e.g., via platform-check in composer.json)?

Integration Approach

Stack Fit

  • Laravel’s Exception Handler: Extend App\Exceptions\Handler::render() with PHP 8.5’s typed properties (e.g., public function render($request, Throwable $exception): Response) for type safety.
  • Middleware Layer: Use Laravel 11’s attribute-based middleware (if available) or traditional middleware to intercept exceptions:
    // Laravel 11+
    #[Middleware(FriendlyExceptionMiddleware::class)]
    public function showErrorPage() { ... }
    
  • Service Provider: Bind the package’s 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');
    });
    

Migration Path

  1. Phase 1: PHP Version Alignment
    • Update Laravel app’s composer.json to PHP 8.1+ (required for Laravel 10/11) and test the package.
    • Use composer why-not to identify dependency conflicts with PHP 8.5.
  2. Phase 2: Integration
    • Replace Handler::render() with the package’s Renderer in a feature branch.
    • Test with APP_DEBUG=true and PHP 8.5’s JIT enabled (php.ini).
  3. Phase 3: Customization
    • Extend the package’s Renderer to use Laravel’s HttpResponse or JsonResponse for API errors.
    • Override Blade templates to support PHP 8.5’s new syntax (e.g., named arguments in @foreach).

Compatibility

  • Laravel Versions:
    • 10.x/11.x: Full compatibility; leverage PHP 8.5 features if needed.
    • 9.x: Test with PHP 8.0–8.1; avoid PHP 8.5-specific code paths.
  • PHP Versions:
    • 7.4: Unsupported; migrate to PHP 8.1+.
    • 8.0–8.5: Supported, but validate Illuminate package versions (e.g., illuminate/support v9.x+).
  • Third-Party Packages: Check for conflicts with:
    • whoops (error pages): May duplicate functionality; configure exclusivity.
    • laravel-debugbar: Ensure stack traces align between tools.

Sequencing

  1. Sandbox Testing:
    • Spin up a Laravel 11 + PHP 8.5 environment and integrate the package in isolation.
    • Test with php -d opcache.jit_buffer_size=100M to simulate JIT impact.
  2. Incremental Rollout:
    • Deploy to non-critical routes first (e.g., /health).
    • Monitor with Laravel Telescope for rendering errors.
  3. Fallback Plan:
    • Implement a try-catch in middleware to fall back to Laravel’s default handler if the package fails.

Operational Impact

Maintenance

  • Dependency Updates:
    • Pin yiisoft/friendly-exception to ^1.2 in composer.json to avoid PHP 8.5+ breaking changes.
    • Use composer why to audit Symfony component versions (e.g., symfony/http-foundation).
  • Configuration Drift:
    • Document PHP version requirements in README.md and CI templates (e.g., GitHub Actions).
    • Example .env:
      FRIENDLY_EXCEPTION_PHP_VERSION=8.5
      FRIENDLY_EXCEPTION_CACHE_DRIVER=file
      
  • Custom Extensions:
    • Maintain a app/Exceptions/FriendlyRenderer.php extension for Laravel-specific logic (e.g., route debugging).

Support

  • Developer Onboarding:
    • Train teams on PHP 8.5’s new error messages (e.g., TypeError for undefined array offsets).
    • Provide a cheat sheet for interpreting the package’s structured output in Laravel’s context.
  • Production Debugging:
    • Configure Sentry or Laravel Log to capture FriendlyExceptionRenderer events with context:
      Sentry\configureScope(function ($scope) {
          $scope->setExtra('exception_renderer', 'friendly');
      });
      
  • Community Resources:

Scaling

  • Performance:
    • Cache rendered error pages in Laravel’s file or redis cache:
      Cache::remember('error_500', 3600, fn() => $renderer->render($exception));
      
    • Profile with php -d xdebug.mode=profile to identify bottlenecks.
  • Distributed Systems:
    • For APIs, extend the package to return JSON errors with HTTP status codes:
      return response()->json(['error' => $renderer->getMessage()], 500);
      
  • Multi-Environment:
    • Use Laravel’s config('app.env') to switch renderers:
      $renderer = config('app.env') === 'production'
          ? new ProdRenderer()
          : new DevRenderer();
      

Failure Modes

  • Silent Failures:
    • Wrap package usage in middleware with a fallback:
      try {
          return $renderer->render($exception);
      } catch (Throwable $e) {
          return new Response("Error rendering exception", 500);
      }
      
  • Data Leakage:
    • Sanitize stack traces in production:
      $renderer->setSensitiveDataFilter(fn($data) => str_replace(base_path(), '[path]', $data));
      
  • Template Errors:
    • Validate Blade templates with php artisan view:clear and test edge cases (e.g., empty exception messages).

Ramp-Up

  • Training:
    • Host a workshop on:
      • PHP 8.5’s impact on error handling (e.g
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope