Skip to content

Commit

Permalink
[1.x] Fixes exception as string (#22)
Browse files Browse the repository at this point in the history
* Fixes exception as string

* Fixes static analysis
  • Loading branch information
nunomaduro authored Nov 23, 2023
1 parent 3f8b803 commit e08b64a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Queue\Events\JobExceptionOccurred;
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Support\Facades\Auth;
use Throwable;

class Handler
{
Expand Down Expand Up @@ -99,10 +100,10 @@ protected function context(MessageLogged $messageLogged): array
}

$context['__pail']['origin']['trace'] = isset($messageLogged->context['exception'])
? collect($messageLogged->context['exception']->getTrace()) // @phpstan-ignore-line
->filter(fn (array $frame) => isset($frame['file'])) // @phpstan-ignore-line
->map(fn (array $frame) => [ // @phpstan-ignore-line
'file' => $frame['file'],
&& $messageLogged->context['exception'] instanceof Throwable ? collect($messageLogged->context['exception']->getTrace())
->filter(fn (array $frame) => isset($frame['file']))
->map(fn (array $frame) => [
'file' => $frame['file'], // @phpstan-ignore-line
'line' => $frame['line'] ?? null,
])->values()
: null;
Expand Down
19 changes: 19 additions & 0 deletions tests/Features/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,22 @@

EOF, verbose: true);
});

test('exception key as string', function () {
expect([
'Log::error("log message", ["exception" => "an exception occured"])',
'throw new Exception("my exception message")',
])->toPail(<<<'EOF'
┌ 2024-01-01 03:04:05 ERROR ──────────────────────
│ log message
│ 1. app/MyClass.php:12
│ 2. app/MyClass.php:34
└──────────────────────────────────────── artisan
┌ 2024-01-01 03:04:05 Exception app/MyClass.php:12
│ my exception message
│ 1. app/MyClass.php:12
│ 2. app/MyClass.php:34
└──────────────────────────────────────── artisan

EOF, verbose: true);
});

0 comments on commit e08b64a

Please sign in to comment.