Skip to content

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

Merged
merged 1 commit into from
May 23, 2016
Merged

Catch \Throwable #18765

merged 1 commit into from
May 23, 2016

Conversation

fprochazka
Copy link
Contributor

@fprochazka fprochazka commented May 12, 2016

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.

@stof
Copy link
Member

stof commented May 12, 2016

some of these changes should actually be done in 2.3 or in 2.7 too. Can you open 3 PRs instead ?

  • one for 2.3 changing all affected places relevant for 2.3
  • another one for 2.7 changing the places relevant in 2.7+ (not changing the places already changed in the previous PR)
  • another one for 2.8 for 2.8+ changes (you can update the current PR for that by removing parts of the patch as it already targets the 2.8 branch)

@fprochazka
Copy link
Contributor Author

I wasn't aware the 2.3 is still maintained :) I'll do that then.

@fprochazka
Copy link
Contributor Author

@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.

@fprochazka fprochazka force-pushed the php7-throwable branch 5 times, most recently from eeae733 to 0fd9ef3 Compare May 12, 2016 17:01

namespace Symfony\Component\Console\Exception;

class FatalThrowableError extends \ErrorException
Copy link
Contributor Author

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.

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

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

Copy link
Contributor Author

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 👍

@fprochazka fprochazka changed the title Catch \Throwable where finally cannot be used Catch \Throwable May 12, 2016
$e->getCode(),
$severity,
$e->getFile(),
$e->getLine()
Copy link
Contributor Author

@fprochazka fprochazka May 13, 2016

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.

Copy link
Member

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).

@nicolas-grekas
Copy link
Member

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.
Should be thought on a case by case basis.

@stof
Copy link
Member

stof commented May 13, 2016

yeah, catching them is fine in places where they are rethrown after some cleanup (use case for finally in newer versions of PHP), but other places should probably let them bubble most of the time

@@ -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) {
Copy link
Member

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) {
Copy link
Member

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

@nicolas-grekas
Copy link
Member

nicolas-grekas commented May 15, 2016

@fprochazka thanks for this PR. I added a comment everywhere I think catching Throwable should be reverted. All the other non-commented places look fine to me.


// 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);
Copy link
Contributor Author

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?

@fprochazka
Copy link
Contributor Author

@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.

@fprochazka fprochazka force-pushed the php7-throwable branch 5 times, most recently from 1b61b94 to 76f5f90 Compare May 19, 2016 12:08
@fprochazka
Copy link
Contributor Author

fprochazka commented May 19, 2016

All the comments are solved, so I'm gonna start spliting this to more branches as @stof said

This was referenced May 19, 2016
@fprochazka fprochazka force-pushed the php7-throwable branch 2 times, most recently from 38b4d5c to de671f4 Compare May 19, 2016 14:07
@fprochazka
Copy link
Contributor Author

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.

@nicolas-grekas
Copy link
Member

👍

@xabbuh
Copy link
Member

xabbuh commented May 23, 2016

👍

fabpot added a commit that referenced this pull request May 23, 2016
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
@fabpot
Copy link
Member

fabpot commented May 23, 2016

Thank you @fprochazka.

@fabpot fabpot merged commit de671f4 into symfony:2.8 May 23, 2016
fabpot added a commit that referenced this pull request May 23, 2016
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
@fprochazka fprochazka deleted the php7-throwable branch May 23, 2016 13:31
@fabpot fabpot mentioned this pull request May 26, 2016
nicolas-grekas added a commit that referenced this pull request May 30, 2016
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
This was referenced Jun 6, 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.

6 participants