PHPStan does not report uncaught exceptions thrown from generators or yield from #13932
Unanswered
DaisukeDaisuke
asked this question in
Support
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Consider the following case:
https://phpstan.org/r/a94992e1-9575-41f6-aada-3632992a7eca
Oops, I seem to have made a mistake copying the shared link. I've fixed it
loop()can interrupt the coroutine by throwing aRuntimeExceptionwith a 10 percent probability, and it declares@throws \RuntimeException.In
main(), this generator is iterated withforeach, so an exception may be propagated, but thetry-catchblock is commented out.Even in this situation, PHPStan does not appear to report any error.
error()always interrupts the coroutine by throwing aRuntimeExceptionafter yielding a value, and it also declares@throws \RuntimeException.However, in
main2(), the exception is mistakenly not caught. Despite this, PHPStan still does not seem to report any error.A local phpstan v2.1.33 with the following rule enabled will continue to ignore exceptions from the generator:
Is this behavior to handle some cases?
Is this because phpstan believes it cannot perform static analysis on delayed execution?
Even if you do implement this, it's recommended to leave it as an option and disable it by default
How can I get phpstan to report these errors?
Beta Was this translation helpful? Give feedback.
All reactions