8000 [Console] Give errors back to error handler if not handled by console.error listeners by chalasr · Pull Request #22261 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Give errors back to error handler if not handled by console.error listeners #22261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Console] Give errors back to error handlers if not handled by consol…
…e.error listeners
  • Loading branch information
chalasr committed Apr 4, 2017
commit 5a5bf54d378210a1b970d4f3853583e72379c621
3 changes: 3 additions & 0 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ public function run(InputInterface $input = null, OutputInterface $output = null
$e = null;
$exitCode = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically, the debug handler handles the exception (rendering it in a special way), but could still want to use a failure exit code. We should let the event change the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's the conclusion we came to with @chalasr regarding this part. I guess now it's better to wait for a PR with a bigger vision of the remaining issues with the component, as @nicolas-grekas seems to plan.

} 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
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,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