8000 added catching of php7 fatal exceptions in application #20110 by bozerkins · Pull Request #20111 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

added catching of php7 fatal exceptions in application #20110 #20111

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 5 commits into from
Closed
Changes from 1 commit
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
Next Next commit
added catching of php7 fatal exceptions
- added new private method to application, which would process the exception and return the exit code / throw it
- added another catch into command run method, which would ensure that under PHP7 all exceptions are being catched as well
  • Loading branch information
Bogdans Ozerkins committed Sep 30, 2016
commit 54d7fc2c0782384021c34f1f49e728802a7bc539
55 changes: 36 additions & 19 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,25 +123,9 @@ public function run(InputInterface $input = null, OutputInterface $output = null
try {
$exitCode = $this->doRun($input, $output);
} catch (\Exception $e) {
if (!$this->catchExceptions) {
throw $e;
}

if ($output instanceof ConsoleOutputInterface) {
$this->renderException($e, $output->getErrorOutput());
} else {
$this->renderException($e, $output);
}

$exitCode = $e->getCode();
if (is_numeric($exitCode)) {
$exitCode = (int) $exitCode;
if (0 === $exitCode) {
$exitCode = 1;
}
} else {
$exitCode = 1;
}
$exitCode = $this->handleCommandRunException($e, $output);
} catch (\Throwable $e) {
$exitCode = $this->handleCommandRunException($e, $output);
}

if ($this->autoExit) {
Expand All @@ -155,6 +139,39 @@ public function run(InputInterface $input = null, OutputInterface $output = null
return $exitCode;
}

/**
* Handler command run exception and provides with the exit code in return
*
* @param \Exception|\Throwable $e
* @param OutputInterface $output
* @return int|mixed
* @throws \Throwable
*/
private function handleCommandRunException($e, OutputInterface $output)
{
if (!$this->catchExceptions) {
throw $e;
}

if ($output instanceof ConsoleOutputInterface) {
$this->renderException($e, $output->getErrorOutput());
} else {
$this->renderException($e, $output);
Copy link
Contributor

Choose a reason for hiding this comment

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

The phpdoc of renderException with @param \Exception $e is not correct anymore and needs to be updated too.

Copy link
Author

Choose a reason for hiding this comment

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

done some changes. took the approach of #19813

now should be just fine

}

$exitCode = $e->getCode();
if (is_numeric($exitCode)) {
$exitCode = (int) $exitCode;
if (0 === $exitCode) {
$exitCode = 1;
}
} else {
$exitCode = 1;
}

return $exitCode;
}

/**
* Runs the current application.
*
Expand Down
0