8000 bug #22261 [Console] Give errors back to error handler if not handled… · symfony/symfony@6e54cdf · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e54cdf

Browse files
committed
bug #22261 [Console] Give errors back to error handler if not handled by console.error listeners (chalasr)
This PR was merged into the 3.3-dev branch. Discussion ---------- [Console] Give errors back to error handler if not handled by console.error listeners | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22259 | License | MIT | Doc PR | n/a Re-throws errors if `ConsoleErrorEvent::markErrorAsHandled()` hasn't been called so that they can reach the global error handler, fixing the BC break. Commits ------- 5a5bf54 [Console] Give errors back to error handlers if not handled by console.error listeners
2 parents a146e4d + 5a5bf54 commit 6e54cdf

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ public function run(InputInterface $input = null, OutputInterface $output = null
138138
$e = null;
139139
$exitCode = 0;
140140
} else {
141+
if (!$e instanceof \Exception) {
142+
throw $e;
143+
}
141144
$exitCode = $e->getCode();
142145
}
143146

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,30 @@ public function testRunWithError()
11161116
$tester->run(array('command' => 'dym'));
11171117
}
11181118

1119+
/**
1120+
* @requires PHP 7
1121+
*/
1122+
public function testErrorIsRethrownIfNotHandledByConsoleErrorEvent()
1123+
{
1124+
$application = new Application();
1125+
$application->setAutoExit(false);
1126+
$application->setDispatcher(new EventDispatcher());
1127+
1128+
$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
1129+
new \UnknownClass();
1130+
});
1131+
1132+
$tester = new ApplicationTester($application);
1133+
1134+
try {
1135+
$tester->run(array('command' => 'dym'));
1136+
$this->fail('->run() should rethrow PHP errors if not handled via ConsoleErrorEvent.');
1137+
} catch (\Throwable $e) {
1138+
$this->assertInstanceOf('Error', $e);
1139+
$this->assertSame($e->getMessage(), 'Class \'UnknownClass\' not found');
1140+
}
1141+
}
1142+
11191143
/**
11201144
* @expectedException \LogicException
11211145
* @expectedExceptionMessage error

0 commit comments

Comments
 (0)
0