-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Catch \Throwable #18765
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
Catch \Throwable #18765
Conversation
some of these changes should actually be done in 2.3 or in 2.7 too. Can you open 3 PRs instead ?
|
I wasn't aware the 2.3 is still maintained :) I'll do that then. |
@stof I think it would be more productive to have 90% of the discussion under one PR and I can split it after this is cleaned, so I'm not doing it over 4 branches. |
eeae733
to
0fd9ef3
Compare
|
||
namespace Symfony\Component\Console\Exception; | ||
|
||
class FatalThrowableError extends \ErrorException |
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.
This, and the other one in Security/Http
are copied from Symfony\Component\Debug\Exception\FatalErrorException
, since there is no direct dependency.
0fd9ef3
to
fab7d23
Compare
@@ -94,6 +97,8 @@ public function load($resource, $type = null) | |||
$controller = $this->parser->parse($controller); | |||
} catch (\Exception $e) { | |||
// unable to optimize unknown notation | |||
} catch (\Throwable $e) { | |||
// unable to optimize unknown notation |
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.
-1 for this one. Getting an Error in the parser should not happen when it is an unknown notation (the parser is expected to throw an Exception in such case), so it would only hide bugs
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.
Makes sense, having it more specific and only throw away something, not everything seems more sane 👍
$e->getCode(), | ||
$severity, | ||
$e->getFile(), | ||
$e->getLine() |
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.
Btw, why is the Throwable
not added as previous in Symfony\Component\Debug\Exception\FatalThrowableError
? It doesn't feel right to throw it away completely.
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.
The original is not thrown away: the state of the new FatalThrowableError has all bits from the original Error exception. Adding it as previous would defeat the purpose of FatalThrowableError, which is to pass the \Exception type hints (even for exceptions in the previous chain).
I'm mostly 👎 but on a few spots: \Error should not be dealt with as regular exceptions. They are a sign of serious issues and recovering after them is encouraging not fixing the related issues to me. |
yeah, catching them is fine in places where they are rethrown after some cleanup (use case for |
@@ -148,6 +148,9 @@ protected function execute(InputInterface $input, OutputInterface $output) | |||
} catch (\Exception $e) { | |||
$exitCode = 1; | |||
$rows[] = array(sprintf('<fg=red;options=bold>%s</>', '\\' === DIRECTORY_SEPARATOR ? 'ERROR' : "\xE2\x9C\x98" /* HEAVY BALLOT X (U+2718) */), $message, $e->getMessage()); | |||
} catch (\Throwable $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.
should be removed
// the response that comes back is simply ignored | ||
if (isset($options['ignore_errors']) && $options['ignore_errors'] && $this->dispatcher) { | ||
$event = new GetResponseForExceptionEvent($this->kernel, $request, HttpKernelInterface::SUB_REQUEST, $e); | ||
} catch (\Throwable $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.
should be reverted OR discussed in a dedicated PR
@fprochazka thanks for this PR. I added a comment everywhere I think catching |
|
||
// Using user_error() here is on purpose so we do not forget | ||
// that this alias also should work alongside with trigger_error(). | ||
return user_error($e, E_USER_ERROR); |
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... should I still create a testcase for this with new fixture for throwable?
@nicolas-grekas I've removed those where I agree, but I would like a better reasoning behind those I left untouched, that you've commented. They seem important to me. |
1b61b94
to
76f5f90
Compare
All the comments are solved, so I'm gonna start spliting this to more branches as @stof said |
38b4d5c
to
de671f4
Compare
Should I try to help with PR for 3.0? Or will the mergers solve the possible conflicts and throw away changes that are not relevant in 3.0? As I'm sure there will be some. |
👍 |
👍 |
This PR was merged into the 2.7 branch. Discussion ---------- Catch \Throwable | Q | A | ------------- | --- | Branch? | 2.7, 2.8, 3.0 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | Yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Related #18765, #15949 Depends on #18812 Commits ------- 103526b Catch \Throwable
Thank you @fprochazka. |
This PR was merged into the 2.8 branch. Discussion ---------- Catch \Throwable | Q | A | ------------- | --- | Branch? | 2.8, 3.0 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | Mostly! | Fixed tickets | n/a | License | MIT | Doc PR | n/a The first commit is based on #15949 Depends on #18813, #18812 ---- I'm new to symfony, so I'm not sure where are all the places where it makes sense to actually catch the throwable and where not. I added most places that seemed logical and when I wasn't sure, I added it anyway. I'm hoping you guys (and girls?) can point out the places where the catch should not be added, I'll fix it and then I can create several PR's for the older branches. A lot of this IMHO should go also to 3.0. Commits ------- de671f4 Catch \Throwable
This PR was squashed before being merged into the 2.3 branch (closes #18812). Discussion ---------- Catch \Throwable | Q | A | ------------- | --- | Branch? | 2.3, 2.7, 2.8, 3.0 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | Yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Related #18765, #15949 Commits ------- 893cf00 Catch \Throwable
The first commit is based on #15949
Depends on #18813, #18812
I'm new to symfony, so I'm not sure where are all the places where it makes sense to actually catch the throwable and where not. I added most places that seemed logical and when I wasn't sure, I added it anyway. I'm hoping you guys (and girls?) can point out the places where the catch should not be added, I'll fix it and then I can create several PR's for the older branches. A lot of this IMHO should go also to 3.0.