Skip to content

Commit

Permalink
Improve internal file detection
Browse files Browse the repository at this point in the history
  • Loading branch information
jessarcher committed Nov 2, 2023
1 parent a151926 commit 19f6d10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Recorders/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,23 @@ 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());
}

return $this->formatLocation($firstNonVendorFrame['file'] ?? 'unknown', $firstNonVendorFrame['line'] ?? null);
}

/**
* 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');
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Recorders/SlowQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down

0 comments on commit 19f6d10

Please sign in to comment.