-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Allow Application to handle PHP 7 Errors #20808
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ class Application | |
private $name; | ||
private $version; | ||
private $catchExceptions = true; | ||
private $catchErrors = false; | ||
private $autoExit = true; | ||
private $definition; | ||
private $helperSet; | ||
|
@@ -100,8 +101,6 @@ public function setDispatcher(EventDispatcherInterface $dispatcher) | |
* @param OutputInterface $output An Output instance | ||
* | ||
* @return int 0 if everything went fine, or an error code | ||
* | ||
* @throws \Exception When doRun returns Exception | ||
*/ | ||
public function run(InputInterface $input = null, OutputInterface $output = null) | ||
{ | ||
|
@@ -124,7 +123,14 @@ public function run(InputInterface $input = null, OutputInterface $output = null | |
if (!$this->catchExceptions) { | ||
throw $e; | ||
} | ||
} catch (\Error $e) { | ||
if (!$this->catchErrors) { | ||
throw $e; | ||
} | ||
$e = new FatalThrowableError($e); | ||
} | ||
|
||
if (isset($e)) { | ||
if ($output instanceof ConsoleOutputInterface) { | ||
$this->renderException($e, $output->getErrorOutput()); | ||
} else { | ||
|
@@ -271,6 +277,22 @@ public function setCatchExceptions($boolean) | |
$this->catchExceptions = (bool) $boolean; | ||
} | ||
|
||
/** | ||
* @return bool Whether errors are caught or not during commands execution | ||
*/ | ||
public function areErrorsCaught() | ||
{ | ||
return $this->catchErrors; | ||
} | ||
|
||
/** | ||
* @param bool $boolean Whether to catch errors or not during commands execution | ||
*/ | ||
public function setCatchErrors($boolean) | ||
{ | ||
$this->catchErrors = (bool) $boolean; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The addition of these 2 methods does not seem related to this PR and should be removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
IMHO, we still have to differentiate exceptions from errors, as the last ones are currently handled in the full stack framework by the handler registered through the Debug component and the Using full stack:
versus the console component standalone, with the
(stack traces are the same) Thus the second Also see #19813 (comment) |
||
|
||
/** | ||
* Gets whether to automatically exit after a command execution or not. | ||
* | ||
|
@@ -814,8 +836,6 @@ protected function configureIO(InputInterface $input, OutputInterface $output) | |
* @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 | ||
*/ | ||
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn’t this be
\Throwable
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
Throwable
would make thecatchErrors
flag catch both exceptions and errors, where there already is a dedicated flag for exceptions.So, if we keep both flags (and I still think we need it currently, as I tried to explain in my previous comments, unless we find a better alternative :/ ), it should probably remains
\Error
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed!