From 19f6d10952de61fd54c4ae8a891df4e5f31b44ec Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Thu, 2 Nov 2023 14:55:18 +1000 Subject: [PATCH] Improve internal file detection --- src/Recorders/Exceptions.php | 12 +++++++----- src/Recorders/SlowQueries.php | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Recorders/Exceptions.php b/src/Recorders/Exceptions.php index 3c38a38d..704ff78f 100644 --- a/src/Recorders/Exceptions.php +++ b/src/Recorders/Exceptions.php @@ -112,9 +112,9 @@ protected function getLocationFromViewException(Throwable $e): string protected function getLocation(Throwable $e): string { $firstNonVendorFrame = collect($e->getTrace()) - ->firstWhere(fn (array $frame) => isset($frame['file']) && $this->isNonVendorFile($frame['file'])); + ->firstWhere(fn (array $frame) => isset($frame['file']) && ! $this->isInternalFile($frame['file'])); - if ($this->isNonVendorFile($e->getFile()) || $firstNonVendorFrame === null) { + if (! $this->isInternalFile($e->getFile()) || $firstNonVendorFrame === null) { return $this->formatLocation($e->getFile(), $e->getLine()); } @@ -122,11 +122,13 @@ protected function getLocation(Throwable $e): string } /** - * Determine whether a file is in the vendor directory. + * Determine whether a file should be considered internal. */ - protected function isNonVendorFile(string $file): bool + protected function isInternalFile(string $file): bool { - return ! Str::startsWith($file, base_path('vendor')); + return Str::startsWith($file, base_path('vendor')) + || $file === base_path('artisan') + || $file === public_path('index.php'); } /** diff --git a/src/Recorders/SlowQueries.php b/src/Recorders/SlowQueries.php index 874310a0..64ab209d 100644 --- a/src/Recorders/SlowQueries.php +++ b/src/Recorders/SlowQueries.php @@ -86,6 +86,7 @@ protected function isInternalFile(string $file): bool { return Str::startsWith($file, base_path('vendor/laravel/pulse')) || Str::startsWith($file, base_path('vendor/laravel/framework')) + || $file === base_path('artisan') || $file === public_path('index.php'); }