Skip to content

Commit 05240ce

Browse files
committed
bug symfony#22690 [Console] Fix errors not rethrown even if not handled by console.error listeners (chalasr)
This PR was merged into the 2.7 branch. Discussion ---------- [Console] Fix errors not rethrown even if not handled by console.error listeners | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#22678 | License | MIT | Doc PR | n/a symfony#22261 has been squashed while revisiting error handling, this fixes it again while keeping latest changes intact. __code__ ```php public function execute(InputInterface $input, OutputInterface $output) { $this->barr(); } public function bar() { } ``` __before__ ![before](http://image.prntscr.com/image/38aa3b46fed6439ead693908ab104fb3.png) __after__ ![after](http://image.prntscr.com/image/071322bfa52247c6a02eac6ef9d8284a.png) Commits ------- 75f098f Fix errors not rethrown even if not handled by console.error listeners
2 parents 0ad2f2e + 75f098f commit 05240ce

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)