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

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

wants to merge 5 commits into from

Conversation

bozerkins
Copy link

@bozerkins bozerkins commented Sep 30, 2016

Q A
Branch? 2.8 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #20110
License MIT
Doc PR - - -
  • 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

- 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
@nicolas-grekas
Copy link
Member

Doesn't #19813 fix the issue?

@bozerkins
Copy link
Author

bozerkins commented Sep 30, 2016

partially.

when no dispatcher is present - the fatal exceptions will not be catched anyways.

https://github.com/fonsecas72/symfony/blob/65e53ece4c867dc0447d3a215fdda8170e163745/src/Symfony/Component/Console/Application.php#L845

though i liked the approach. i could adjust this PR so it creates a FatalThrowableError object and works with that.

this way we'd avoid creating another method

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

Bogdans Ozerkins added 2 commits October 1, 2016 15:18
- implemented compatibilit with PHP7 fatal errors
- using FatalThrowableError for BC with PHP5
if (!$this->catchExceptions) {
throw $e;
throw $exception;
Copy link
Member

@nicolas-grekas nicolas-grekas Oct 3, 2016

Choose a reason for hiding this comment

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

$e should be thrown here, not $exception (no wrapper)

Copy link
Author

Choose a reason for hiding this comment

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

you mean FatalThrowableError should not be here at all?

Copy link
Member

Choose a reason for hiding this comment

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

yes, when rethrowing, the original exception should be thrown

@bozerkins
Copy link
Author

done. now the changes have become as simple and straight forward as possible

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Oct 5, 2016

Let's change the type hint (doc comment) on the renderException method also (Throwable instead of Exception), that would be consistent with what is done here

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Oct 6, 2016

Here is the patch I propose to finish this PR:

--- a/src/Symfony/Component/Console/Application.php
+++ b/src/Symfony/Component/Console/Application.php
@@ -102,8 +102,6 @@ class Application
      * @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)
     {
@@ -634,7 +632,7 @@ class Application
     /**
      * Renders a caught exception.
      *
-     * @param \Exception      $e      An exception instance
+     * @param \Throwable      $e      An exception instance
      * @param OutputInterface $output An OutputInterface instance
      */
     public function renderException($e, $output)
@@ -831,8 +829,6 @@ class Application
      * @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)
     {

Note also that it should be merged on 2.7!

@fabpot
Copy link
Member

fabpot commented Nov 10, 2016

@bozerkins Can you take @nicolas-grekas comments into account?

fabpot added a commit that referenced this pull request Dec 5, 2016
…adus)

This PR was squashed before being merged into the 2.7 branch (closes #20736).

Discussion
----------

[Console] fixed PHP7 Errors when not using Dispatcher

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17257, #20110, #20111
| License       | MIT
| Doc PR        | n/a

Original fix, #19813, works only when there is event dispatcher available.
This PR fix the issue also for scenario without event dispatcher.

Closes #20110 issue and #20111 PR connected to it.
Closing #17257 , as everywhere the error is converted to exception and it should be handled

Commits
-------

899fa79 [Console] fixed PHP7 Errors when not using Dispatcher
@fabpot fabpot closed this Dec 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants