From 4138e0c0957537779c6679dc3d1486637ee93d36 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 3 Nov 2024 17:03:54 +0000 Subject: [PATCH 1/2] Add exception handler to report exceptions in console --- src/Exceptions/Handler.php | 14 ++++++++++++++ src/NativeServiceProvider.php | 6 ++++++ 2 files changed, 20 insertions(+) create mode 100644 src/Exceptions/Handler.php diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php new file mode 100644 index 0000000..7815371 --- /dev/null +++ b/src/Exceptions/Handler.php @@ -0,0 +1,14 @@ +reportable(function (\Throwable $e) { + error_log('[NATIVE_EXCEPTION]: '.$e->getMessage()); + }); + } +} diff --git a/src/NativeServiceProvider.php b/src/NativeServiceProvider.php index 92f88e4..f6eb5b3 100644 --- a/src/NativeServiceProvider.php +++ b/src/NativeServiceProvider.php @@ -11,6 +11,7 @@ use Native\Laravel\Commands\MinifyApplicationCommand; use Native\Laravel\Commands\SeedDatabaseCommand; use Native\Laravel\Events\EventWatcher; +use Native\Laravel\Exceptions\Handler; use Native\Laravel\Logging\LogWatcher; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -44,6 +45,11 @@ public function packageRegistered() return new MigrateCommand($app['migrator'], $app['events']); }); + $this->app->singleton( + \Illuminate\Contracts\Debug\ExceptionHandler::class, + Handler::class + ); + if (config('nativephp-internal.running')) { Artisan::starting(function ($artisan) { $artisan->resolveCommands([ From 9fe5140caf3bdf9a4e1f8149ff0e378972826830 Mon Sep 17 00:00:00 2001 From: simonhamp Date: Sun, 3 Nov 2024 17:04:26 +0000 Subject: [PATCH 2/2] Fix styling --- src/Exceptions/Handler.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php index 7815371..d1d3c56 100644 --- a/src/Exceptions/Handler.php +++ b/src/Exceptions/Handler.php @@ -2,7 +2,8 @@ namespace Native\Laravel\Exceptions; -class Handler extends \Illuminate\Foundation\Exceptions\Handler { +class Handler extends \Illuminate\Foundation\Exceptions\Handler +{ protected $internalDontReport = []; public function register(): void