Skip to content

Commit 1f3fe0a

Browse files
Merge branch '4.0'
* 4.0: Have weak_vendors ignore deprecations from outside [HttpFoundation] fixed return type of method HeaderBag::get [HttpFoundation] Added "resource" type on Request::create docblock [Console] Fix using finally where the catch can also fail [Process] Skip environment variables with false value in Process Revert "bug #25789 Enableable ArrayNodeDefinition is disabled for empty configuration (kejwmen)" Formatting fix in upgrade 3.0 document don't split lines on carriage returns when dumping trim spaces from unquoted scalar values Revert "bug #25851 [Validator] Conflict with egulias/email-validator 2.0 (emodric)" [DI] compilation perf tweak [Validator] Conflict with egulias/email-validator 2.0 [Validator] add missing parent isset and add test
2 parents bfa956f + 50b538e commit 1f3fe0a

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

Application.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
874874
}
875875

876876
$event = new ConsoleCommandEvent($command, $input, $output);
877+
$e = null;
877878

878879
try {
879880
$this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
@@ -886,13 +887,18 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
886887
} catch (\Throwable $e) {
887888
$event = new ConsoleErrorEvent($input, $output, $e, $command);
888889
$this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
890+
$e = $event->getError();
889891

890-
if (0 !== $exitCode = $event->getExitCode()) {
891-
throw $event->getError();
892+
if (0 === $exitCode = $event->getExitCode()) {
893+
$e = null;
892894
}
893-
} finally {
894-
$event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
895-
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
895+
}
896+
897+
$event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
898+
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
899+
900+
if (null !== $e) {
901+
throw $e;
896902
}
897903

898904
return $event->getExitCode();

Tests/ApplicationTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,34 @@ public function testErrorIsRethrownIfNotHandledByConsoleErrorEventWithCatchingEn
15531553
}
15541554
}
15551555

1556+
/**
1557+
* @expectedException \RuntimeException
1558+
* @expectedExceptionMessage foo
1559+
*/
1560+
public function testThrowingErrorListener()
1561+
{
1562+
$dispatcher = $this->getDispatcher();
1563+
$dispatcher->addListener('console.error', function (ConsoleErrorEvent $event) {
1564+
throw new \RuntimeException('foo');
1565+
});
1566+
1567+
$dispatcher->addListener('console.command', function () {
1568+
throw new \RuntimeException('bar');
1569+
});
1570+
1571+
$application = new Application();
1572+
$application->setDispatcher($dispatcher);
1573+
$application->setAutoExit(false);
1574+
$application->setCatchExceptions(false);
1575+
1576+
$application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {
1577+
$output->write('foo.');
1578+
});
1579+
1580+
$tester = new ApplicationTester($application);
1581+
$tester->run(array('command' => 'foo'));
1582+
}
1583+
15561584
protected function tearDown()
15571585
{
15581586
putenv('SHELL_VERBOSITY');

0 commit comments

Comments
 (0)