Skip to content

[Console] fixed PHP7 Errors are now handled in Application::run and a… #20917

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 1 commit into from

Conversation

jstuhli
Copy link

@jstuhli jstuhli commented Dec 14, 2016

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #20775
License MIT
Doc PR n/a

PRs #19813 and #20736 do not complete solve every problem with PHP7 new \Error class. This PR adds additional catching in Application::run, and as such the Application now returns status code 1 when \Error occurs, and closes #20775.

More info:
If there is no dispatcher, due to #20736 everything will work fine, FatalThrowableError will be rethrown, and that is catched by the try/catch in Application::run.
When there is a dispatcher, but there is no console.exception Listener that modifies the exception, code in PR #19813 will rethrow the original exception (\Error), and not the wrapped one. Since Application:run only catches Exceptions \Error will not get caught by try/catch in Application::run, and as a result status code will be 0, which is obviously wrong.

@ogizanagi
Copy link
Contributor

ogizanagi commented Dec 14, 2016

In #20808, I adopt another approach, because catching \Error and \Exception indistinctly changes the behavior when using the application with the framework and the Debug component for instance.

I.e, with your proposal, you'll get:

[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to undefined method Symfony\Component\Console\Input\ArgvInput::Option()

instead of the current:

[Symfony\Component\Debug\Exception\UndefinedMethodException]
Attempted to call an undefined method named "Option" of class "Symfony\Component\Console\Input\ArgvInput".
Did you mean to call e.g. "getOption", "getOptions", "getParameterOption", "hasOption", "hasParameterOption" or "setOption"?

See #20808 (comment) and #19813 (comment)

Note that you only get a 0 exit code when a command throws an \Error using the framework (due to the Debug component and DebugHandlersListener).
Using the component standalone, you'll get a non 0 exit code (1 or 255, see below).

I just realized there is an inconsistency in 899fa79 because, using the component standalone:

  • when no event dispatcher is injected, a FatalThrowableError is thrown (1 exit code)
  • when an event dispatcher is injected, the original \Error is thrown (255 exit code)

It should always throw the original \Throwable instead, for BC reasons (as expressed in #19813 (comment))

In #20797 I try to fix the issue with commands throwing \Errors in the framework by re-throwing the \Error at the end of the handler which triggers the native exception handler and exit the script with 255.

WDYT?

@jstuhli
Copy link
Author

jstuhli commented Dec 15, 2016

I was guided by the #20736, to have a simple fix for the problem. Rethrow the original exception in case of \Exception, wrap it in FatalThrowableError otherwise.

In any case, which ever solution is chosen, it should go to the 2.7 branch. PHP 7 is being deployed at a fast pace, anybody using symfony and relying on the command exit code will be in for a nasty surprise.

@ogizanagi
Copy link
Contributor

In any case, which ever solution is chosen, it should go to the 2.7 branch. PHP 7 is being deployed at a fast pace, anybody using symfony and relying on the command exit code will be in for a nasty surprise.

#20797 targets 2.7 and solves this issue.

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Dec 27, 2016
@fabpot
Copy link
Member

fabpot commented Mar 22, 2017

Can we close this one?

@jstuhli
Copy link
Author

jstuhli commented Mar 23, 2017

The issue of 0 exit code for throwable exceptions when console is used within the symfony framework on php 7 still exists (due to the DebugHandlersListener).

The fix for this can be either in the Console/Application::run (this PR), or directly in the DebugHandlersListener (PR #20797).

We've been using this fork in production for 3 months, to avoid problems with cli queue workers.

@chalasr
Copy link
Member

chalasr commented May 10, 2017

The wrong exit code has been fixed and \Throwables are handled by the application (well, there is a BC break but this will not help), this should be closed.

@jstuhli jstuhli closed this May 14, 2017
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.

6 participants