-
Notifications
You must be signed in to change notification settings - Fork 199
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
Handling \Throwable in error controller #90
Conversation
throw new \Exception('Should not ever get here'); | ||
} | ||
|
||
private function produceTypeError(): self |
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.
These tests would fail on older versions of php right?
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.
Yes, especially on versions that don't have return types (i.e. <7.0). Maybe they could be mark as skipped based on PHP version... what do you think?
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.
Now i think about it, the rest of the code would also fail on php < 7.0
I havent tried it, but i read that this is the backwards compatible way to do it:
try {
// Code that may throw an Exception or Error.
} catch (Throwable $t) {
// Executed only in PHP 7, will not match in PHP 5.x
} catch (Exception $e) {
// Executed only in PHP 5.x, will not be reached in PHP 7
}
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.
Don't worry about it, my co-worker who I gave permissions in this repo introduced throwable catches into the codebase a couple of weeks ago to solve some type error issues, so I've gone and raised the required php version to 7.0
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.
too bad... we still have some systems running on php 5.6
i'll send a pull request to make it compatible again ok?
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.
Yep that's absolutely fine, I've actually set you as a collaborator now so feel free to merge stuff like that as you see fit. You'll have to change the composer.json value back
Great PR, thank you @tomasfejfar |
There are multiple places where
Exception
is caught instead of\Throwable
. This causes that if any such code inside those method throwsTypeError
such error is not handled in the expected way. There was already some code around action ErrorExceptions, but there was no code regarding ErrorExceptions from plugins.This PR replaces all those places and also adds test that checks that TypeException is correctly propagated.