Skip to content

Commit 75f098f

Browse files
committed
Fix errors not rethrown even if not handled by console.error listeners
1 parent 2f1c28b commit 75f098f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
129129
}
130130

131131
if (null !== $e) {
132-
if (!$this->catchExceptions) {
132+
if (!$this->catchExceptions || !$x instanceof \Exception) {
133133
throw $x;
134134
}
135135

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,29 @@ protected function getDispatcher($skipCommand = false)
11701170

11711171
return $dispatcher;
11721172
}
1173+
1174+
/**
1175+
* @requires PHP 7
1176+
*/
1177+
public function testErrorIsRethrownIfNotHandledByConsoleErrorEventWithCatchingEnabled()
1178+
{
1179+
$application = new Application();
1180+
$application->setAutoExit(false);
1181+
$application->setDispatcher(new EventDispatcher());
1182+
1183+
$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
1184+
new \UnknownClass();
1185+
});
1186+
1187+
$tester = new ApplicationTester($application);
1188+
1189+
try {
1190+
$tester->run(array('command' => 'dym'));
1191+
$this->fail('->run() should rethrow PHP errors if not handled via ConsoleErrorEvent.');
1192+
} catch (\Error $e) {
1193+
$this->assertSame($e->getMessage(), 'Class \'UnknownClass\' not found');
1194+
}
1195+
}
11731196
}
11741197

11751198
class CustomApplication extends Application

0 commit comments

Comments
 (0)