Skip to content

ViewException does not provide dependencies to the wrapped report method #36108

Closed
@imjoehaines

Description

@imjoehaines
  • Laravel Version: 6.20.15 / 8.25.0 / 9.x (8076d86)
  • PHP Version: N/A
  • Database Driver & Version: N/A

Description:

The ViewException class introduced in #36032 does not pass dependencies to the wrapped exception's report method. This causes a fatal error when an exception thrown in a view has a dependency

See the docs:

You may type-hint any required dependencies of the report method and they will automatically be injected into the method by Laravel's service container.
https://laravel.com/docs/8.x/errors#renderable-exceptions

Steps To Reproduce:

  1. Create a new Laravel project
  2. Remove Ignition & Collision (composer remove facade/ignition nunomaduro/collision) [6.x & 8.x only]
  3. Create a custom exception class with a report method that requires dependencies, e.g.:
    namespace App\Exceptions;
    
    class MyException extends \Exception
    {
        public function report(\Illuminate\Contracts\Auth\Guard $guard)
        {
            return false;
        }
    }
  4. Throw an instance of this exception in a view
  5. An ArgumentCountError is thrown:

    Too few arguments to function App\Exceptions\MyException::report()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions