Skip to content

Commit 9a0d2c2

Browse files
committed
Fix command input handling
1 parent fd85d9b commit 9a0d2c2

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/Sentry/Laravel/EventHandler.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
use Sentry\Breadcrumb;
2828
use Sentry\SentrySdk;
2929
use Sentry\State\Scope;
30+
use Symfony\Component\Console\Input\ArgvInput;
31+
use Symfony\Component\Console\Input\ArrayInput;
32+
use Symfony\Component\Console\Input\InputInterface;
3033

3134
class EventHandler
3235
{
@@ -568,9 +571,9 @@ protected function commandStartingHandler(CommandStarting $event)
568571
Breadcrumb::TYPE_DEFAULT,
569572
'artisan.command',
570573
'Starting Artisan command: ' . $event->command,
571-
method_exists($event->input, '__toString') ? [
572-
'input' => (string)$event->input,
573-
] : []
574+
[
575+
'input' => $this->extractCommandInput($event->input),
576+
]
574577
));
575578
}
576579
}
@@ -588,11 +591,10 @@ protected function commandFinishedHandler(CommandFinished $event)
588591
Breadcrumb::TYPE_DEFAULT,
589592
'artisan.command',
590593
'Finished Artisan command: ' . $event->command,
591-
array_merge([
594+
[
592595
'exit' => $event->exitCode,
593-
], method_exists($event->input, '__toString') ? [
594-
'input' => (string)$event->input,
595-
] : [])
596+
'input' => $this->extractCommandInput($event->input),
597+
]
596598
));
597599
}
598600

@@ -604,6 +606,16 @@ protected function commandFinishedHandler(CommandFinished $event)
604606
Integration::flushEvents();
605607
}
606608

609+
/** @return string|null */
610+
private function extractCommandInput(InputInterface $input)
611+
{
612+
if ($input instanceof ArgvInput) {
613+
return (string)$input;
614+
}
615+
616+
return null;
617+
}
618+
607619
protected function octaneRequestReceivedHandler(Octane\RequestReceived $event): void
608620
{
609621
$this->prepareScopeForOctane();

test/Sentry/CommandInfoInBreadcrumbsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Sentry\Laravel\Tests;
44

55
use Illuminate\Console\Events\CommandStarting;
6-
use Symfony\Component\Console\Input\ArrayInput;
6+
use Symfony\Component\Console\Input\ArgvInput;
77
use Symfony\Component\Console\Output\BufferedOutput;
88

99
class CommandInfoInBreadcrumbsTest extends SentryLaravelTestCase
@@ -55,7 +55,7 @@ private function dispatchCommandStartEvent()
5555
CommandStarting::class,
5656
new CommandStarting(
5757
'test:command',
58-
new ArrayInput(['--foo' => 'bar']),
58+
new ArgvInput(['artisan', '--foo=bar']),
5959
new BufferedOutput()
6060
)
6161
);

0 commit comments

Comments
 (0)