laravel / nova-issues

557 stars 34 forks source link

Nova::report() handler ignored #4790

Closed rubenflush closed 2 years ago

rubenflush commented 2 years ago

Description:

The error reporting documentation is incorrect (see https://nova.laravel.com/docs/4.0/installation.html#error-reporting). Any custom exception handler which is being registered using Nova::report() is being discarded after the NovaExceptionHandler is registered by the NovaApplicationServiceProvider::registerExceptionHandler() method. The 'NovaExceptionHandler::register()' method is executed twice (firstly while binding, secondly when an exception occurs) and the Nova::$reportCallback is not available anymore on second register execution.

Detailed steps to reproduce the issue on a fresh Nova installation:

  1. Add method to NovaServiceProvider as documentation states:
public function register(): void
{
    Nova::report(fn ($exception) => dd('I am invisible'));
}
  1. Trigger exception by adding undefined function to any resource:
public function fields(NovaRequest $request): array
{
    nova_exception_test();
}
  1. Open your Nova admin

You will see the default error handler but instead you would expect to see the debug I am invisible.

Workaround

The workaround for this issue is to register the handler as a singleton in the NovaServiceProvider:

protected function registerExceptionHandler()
{
    app()->singleton(ExceptionHandler::class, NovaExceptionHandler::class);
}
github-actions[bot] commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.