Skip to content

Commit 3266fd5

Browse files
committed
Fix a possible bug that could make Sentry crash if an error is triggered before loading a console command
1 parent 561967d commit 3266fd5

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1515
- The `SentrySymfonyClient` is no longer an optional argument of `ExceptionListener`; it's now required
1616
### Fixed
1717
- Remove usage of create_function to avoid deprecations (#71)
18+
- Fix a possible bug that could make Sentry crash if an error is triggered before loading a console command
1819
### Removed
1920
- Drop deprecated fields from configuration; the same options can be used (since 0.8.3) under `sentry.options`
2021
- Dropped the third argument from the `SentrySymfonyClient` constructor; `error_types` are now fetched from the second argument, the options array

src/EventListener/ExceptionListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function onConsoleException(ConsoleExceptionEvent $event)
134134

135135
$data = [
136136
'tags' => [
137-
'command' => $command->getName(),
137+
'command' => $command ? $command->getName() : 'N/A',
138138
'status_code' => $event->getExitCode(),
139139
],
140140
];

test/EventListener/ExceptionListenerTest.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -464,18 +464,13 @@ public function test_that_it_captures_exception()
464464
$listener->onKernelException($mockEvent);
465465
}
466466

467-
public function test_that_it_captures_console_exception()
467+
/**
468+
* @dataProvider mockCommandProvider
469+
*/
470+
public function test_that_it_captures_console_exception(Command $mockCommand = null, $expectedCommandName)
468471
{
469472
$reportableException = new \Exception();
470473

471-
$mockCommand = $this->createMock(Command::class);
472-
473-
$mockCommand
474-
->expects($this->once())
475-
->method('getName')
476-
->willReturn('cmd name')
477-
;
478-
479474
$mockEvent = $this->createMock(ConsoleExceptionEvent::class);
480475

481476
$mockEvent
@@ -509,7 +504,7 @@ public function test_that_it_captures_console_exception()
509504
$this->identicalTo($reportableException),
510505
$this->identicalTo([
511506
'tags' => [
512-
'command' => 'cmd name',
507+
'command' => $expectedCommandName,
513508
'status_code' => 10,
514509
],
515510
])
@@ -521,6 +516,21 @@ public function test_that_it_captures_console_exception()
521516
$listener->onConsoleException($mockEvent);
522517
}
523518

519+
public function mockCommandProvider()
520+
{
521+
$mockCommand = $this->createMock(Command::class);
522+
$mockCommand
523+
->expects($this->once())
524+
->method('getName')
525+
->willReturn('cmd name')
526+
;
527+
528+
return [
529+
[$mockCommand, 'cmd name'],
530+
[null, 'N/A'], // the error may have been triggered before the command is loaded
531+
];
532+
}
533+
524534
public function test_that_it_can_replace_client()
525535
{
526536
$replacementClient = $this->createMock('Raven_Client');

0 commit comments

Comments
 (0)