nWidart / laravel-modules

Module Management In Laravel
https://docs.laravelmodules.com
MIT License
5.5k stars 954 forks source link

module based error handling #1868

Closed TerrePorter closed 3 months ago

TerrePorter commented 3 months ago

I am using Laravel 11.9.2 and nwidart/laravel-modules version 11.0.1. With the change to how exceptions are handled, ie…

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        // api: __DIR__.'/../routes/api.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        //
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();

My module custom error handler code is no longer functioning. I’ve attempted to return to the old style that had a error handler class as each of my modules handle their own errors and I don’t want to have all the error code in the base code but contained in the module. Here is how I have done this. In my base AppServiceProvider I have added this to the register function

use App\Exceptions\Handler;
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
class AppServiceProvider extends ServiceProvider
{
public function register(): void
 {
$this->app->singleton(ExceptionHandlerContract::class, Handler::class);
}
}

And commented out the withExceptions on the app.php file. The base handler has the code to load the module error handler code. This works in the browser and my module exceptions are running, but when using console commands I get an error message,

[Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable.

I’m not sure if this is a bug or not, or who’s it would be.

Is there a way to implement module based error handling?

TerrePorter commented 3 months ago

I am leaning toward this being a laravel issue so i posted a issue with them, https://github.com/laravel/framework/issues/51730