-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] fixed PHP7 Errors are now handled and converted to Exceptions #19813
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
Conversation
fonsecas72
commented
Sep 1, 2016
Q | A |
---|---|
Branch? | 2.7 |
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #18484 |
License | MIT |
Doc PR |
Test would be great for this. |
$event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode()); | ||
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event); | ||
|
||
throw $e; |
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 we be throwing the original throwable here. This is a BC break?
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.
I agree
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.
What does it mean?
That I should delete the $e = new FatalThrowableError($e);
line?
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.
I propose this:
try {
$e = null;
$exitCode = $command->run($input, $output);
} catch (\Exception $x) {
$e = $x;
} catch (\Throwable $x) {
$e = new FatalThrowableError($x);
}
if (null !== $e) {
$event = new ConsoleExceptionEvent($command, $input, $output, $e, $e->getCode());
$this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
$e = $event->getException();
$event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
throw $x;
}
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.
I think it would be better to just add another function and call that at the end of each try catch?
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.
try {
$exitCode = $command->run($input, $output);
} catch (\Exception $e) {
$this->someFuntion($e);
throw $e;
} catch (\Throwable $x) {
$this->someFuntion(new FatalThrowableError($e));
throw $e;
}
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.
I will go with whatever solution you find better /cc @nicolas-grekas :)
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.
It's a pure matter of coding style, I don't care :)
Looks like this is untested, can you add a test case please? |
c41c4de
to
1949951
Compare
@nicolas-grekas it's done I believe, thanks |
999beb4
to
a5250fd
Compare
@@ -16,7 +16,8 @@ | |||
} | |||
], | |||
"require": { | |||
"php": ">=5.3.9" | |||
"php": ">=5.3.9", | |||
"symfony/debug": "~2.7,>=2.7.14" |
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.
Should be ~2.7,>=2.7.2
8e1b521
to
93ae8c6
Compare
@@ -16,7 +16,8 @@ | |||
} | |||
], | |||
"require": { | |||
"php": ">=5.3.9" | |||
"php": ">=5.3.9", | |||
"symfony/debug": "~2.7,>=2.7.2" |
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.
^2.7.2
?
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.
also, what about 3.x?
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.
we don't use ^
yet
we'll add 3.x when merging into 2.8 (the only branch that opens to 3.x)
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.
ok :)
@nicolas-grekas the original exception is being re-throw and tests are updated/fixed now |
@@ -914,7 +914,7 @@ public function testRunWithDispatcher() | |||
} | |||
|
|||
/** | |||
* @expectedException \LogicException | |||
* @expectedException \RuntimeException |
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.
So my bad, this can't change, that would be a bc break.
I propose to tweak the implementation like this, so that the original exception is preserved, except when a listener decides to alter it:
try {
$e = null;
$exitCode = $command->run($input, $output);
} catch (\Exception $x) {
$e = $x;
} catch (\Throwable $x) {
$e = new FatalThrowableError($x);
}
if (null !== $e) {
$event = new ConsoleExceptionEvent($command, $input, $output, $e, $e->getCode());
$this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
if ($e !== $event->getException()) {
$x = $e = $event->getException();
}
$event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
throw $x;
}
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.
oh now I get it! I've added a little test for that too. I hope everything is ok now :)
8f16615
to
7c2d7b3
Compare
7c2d7b3
to
65e53ec
Compare
👍 |
Thank you @fonsecas72. |
…to Exceptions (fonsecas72) This PR was squashed before being merged into the 2.7 branch (closes #19813). Discussion ---------- [Console] fixed PHP7 Errors are now handled and converted to Exceptions | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18484 | License | MIT | Doc PR | Commits ------- d3c613b [Console] fixed PHP7 Errors are now handled and converted to Exceptions
Thank you @TomasVotruba @nicolas-grekas @GrahamCampbell 👍 |
@fonsecas72 Glad to help :) |
…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