[SPEED-3094] Support not having a Return or a Throw if an underlying function throws and is not caught#164
Conversation
Return or a Throw if an underlying function throws and is not caught
Return or a Throw if an underlying function throws and is not caughtReturn or a Throw if an underlying function throws and is not caught
jongardiner
left a comment
There was a problem hiding this comment.
I'm sorry, but I don't think I can approve this. It won't cover a lot of real world scenerios where the body is in another file as is, and if we parse external files, we'll take a pretty significant performance hit.
We could maybe do something around methods that are documented to return "never" which is a new return type. (Although I'm not sure throwing counts as returning.)
| * | ||
| * @return bool | ||
| */ | ||
| private function isMethodCallThatThrows(Node\Expr\MethodCall $methodCall): bool { |
There was a problem hiding this comment.
I see what we're doing. We're trying to grab the body of the function that is being called in order to look up whether is contains a throw statement. That's going to work if the function is in the same file, but if it is a function in a different file then it won't be able to get the method body the way that we do here. There is a way to grab the file contents and parse it, but it is a pretty big performance hit. I have a branch where I do some work around declared throws where we don't have to have the method body handy to know if a function might throw. We don't have anything for a method that ALWAYS throws, which I think is what we're looking for here.
Problem:
The following code is legitimate; but guardrail doesn't think it is
Solution:
Check if underlying functions throw.
throwOnlyoption to several functions that previously checked for return or throw