Skip to content

[Console] fixed PHP7 Errors when not using Dispatcher #20736

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
10 changes: 9 additions & 1 deletion src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public function run(InputInterface $input = null, OutputInterface $output = null
* @param OutputInterface $output An Output instance
*
* @return int 0 if everything went fine, or an error code
*
* @throws \Exception when the command being run threw an exception
Copy link
Member

Choose a reason for hiding this comment

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

I still think this should be removed as this is not actionnable.

Copy link
Member Author

Choose a reason for hiding this comment

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

very well.
btw, please check an email

*/
public function doRun(InputInterface $input, OutputInterface $output)
{
Expand Down Expand Up @@ -843,7 +845,13 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
}

if (null === $this->dispatcher) {
return $command->run($input, $output);
try {
return $command->run($input, $output);
} catch (\Exception $e) {
throw $e;
} catch (\Throwable $e) {
throw new FatalThrowableError($e);
}
}

$event = new ConsoleCommandEvent($command, $input, $output);
Expand Down
18 changes: 18 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,24 @@ public function testRunDispatchesAllEventsWithException()
$this->assertContains('before.foo.caught.after.', $tester->getDisplay());
}

public function testRunWithError()
{
$this->setExpectedException('Exception', 'dymerr');

$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);

$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
$output->write('dym.');

throw new \Error('dymerr');
});

$tester = new ApplicationTester($application);
$tester->run(array('command' => 'dym'));
}

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