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

bug-yii2 ErrorHandler can not process when throw Error #106

Open
saltdg opened this issue Sep 24, 2024 · 2 comments
Open

bug-yii2 ErrorHandler can not process when throw Error #106

saltdg opened this issue Sep 24, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@saltdg
Copy link

saltdg commented Sep 24, 2024

try {
$response = $app->handleRequest($yiiRequest);
} catch (\Exception $e) { // can't catch Error and not passed to yii2 ErrorHandler processing.
}

@SamMousa SamMousa added the bug Something isn't working label Sep 24, 2024
@SamMousa
Copy link
Collaborator

Can you make a PR?

@SamMousa
Copy link
Collaborator

SamMousa commented Sep 25, 2024

While reviewing the PR I got to thinking on whether we should change this at all.

Currently the idea is as follows:

  1. Exceptions should not bubble out of your application they should be caught.
  2. In production your ErrorHandler will catch all errors and handle them, but they are still errors.
  3. Exceptions to rule 1 are specific exception classes that are explicitly thrown by the developer, children of UserException.

By passing all errors to the error handler we significantly change this behavior.

In my opinion all tests should fail if you have an error (like a TypeError) in your code. This should never ship to production.

Of course then you're left with a challenge on how to test that your error handler works as expected in cases where such a bug does end up in production. While we know that the error handler itself works it is not unreasonable to want to test your specific configuration of it.

Can you share your thoughts on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants