Skip to content

Commit 3650984

Browse files
committed
Fix command input handling
1 parent fd85d9b commit 3650984

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/Sentry/Laravel/EventHandler.php

Lines changed: 23 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,20 @@ protected function commandFinishedHandler(CommandFinished $event)
604606
Integration::flushEvents();
605607
}
606608

609+
/** @return array|string|null */
610+
private function extractCommandInput(InputInterface $input)
611+
{
612+
$extracted = null;
613+
614+
if ($input instanceof ArgvInput) {
615+
$extracted = (string)$input;
616+
} elseif ($input instanceof ArrayInput) {
617+
$extracted = $input->getArguments();
618+
}
619+
620+
return $extracted;
621+
}
622+
607623
protected function octaneRequestReceivedHandler(Octane\RequestReceived $event): void
608624
{
609625
$this->prepareScopeForOctane();

0 commit comments

Comments
 (0)