Skip to content

Commit

Permalink
bug #22261 [Console] Give errors back to error handler if not handled…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
fabpot committed Apr 4, 2017
2 parents a146e4d + 5a5bf54 commit 6e54cdf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Symfony/Component/Console/Application.php
Expand Up @@ -138,6 +138,9 @@ public function run(InputInterface $input = null, OutputInterface $output = null
$e = null;
$exitCode = 0;
} else {
if (!$e instanceof \Exception) {
throw $e;
}
$exitCode = $e->getCode();
}

Expand Down
24 changes: 24 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Expand Up @@ -1116,6 +1116,30 @@ public function testRunWithError()
$tester->run(array('command' => 'dym'));
}

/**
* @requires PHP 7
*/
public function testErrorIsRethrownIfNotHandledByConsoleErrorEvent()
{
$application = new Application();
$application->setAutoExit(false);
$application->setDispatcher(new EventDispatcher());

$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
new \UnknownClass();
});

$tester = new ApplicationTester($application);

try {
$tester->run(array('command' => 'dym'));
$this->fail('->run() should rethrow PHP errors if not handled via ConsoleErrorEvent.');
} catch (\Throwable $e) {
$this->assertInstanceOf('Error', $e);
$this->assertSame($e->getMessage(), 'Class \'UnknownClass\' not found');
}
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage error
Expand Down

0 comments on commit 6e54cdf

Please sign in to comment.