Skip to content
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

Merged
merged 2 commits into from
Jul 10, 2020

Conversation

tomasfejfar
Copy link

There are multiple places where Exception is caught instead of \Throwable. This causes that if any such code inside those method throws TypeError 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.

@tomasfejfar tomasfejfar changed the title Tf throwable handling Handling \Throwable in error controller Jul 7, 2020
throw new \Exception('Should not ever get here');
}

private function produceTypeError(): self
Copy link
Collaborator

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?

Copy link
Author

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?

Copy link
Collaborator

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
}

Copy link
Owner

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

Copy link
Collaborator

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?

Copy link
Owner

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

@Shardj Shardj merged commit e0f3d88 into Shardj:master Jul 10, 2020
@Shardj
Copy link
Owner

Shardj commented Jul 10, 2020

Great PR, thank you @tomasfejfar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants