-
-
Notifications
You must be signed in to change notification settings - Fork 514
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
Add @throws annotation #287
Conversation
I just added this library to our project and noticed exception throws were missing on higher level interfaces but were added on request interfaces which were used. This would be a nice addition, but I would instead like to request specific exceptions that are thrown by default implementations to be specified on the interfaces instead of the interface. |
f126aa9
to
e2ec9b6
Compare
The interface should be about contract and not about "default implementations". Rather than saying exactly the exception thrown in the default implementation (which is difficult because it can change often) it's generally better to throw an Interface, saying "All theses exceptions could be thrown or not" and if someone else implements the interface he can decide which exceptions from the interface he throws. |
@gehrisandro @nunomaduro I rebased the PR if you have time to take a look :) Thanks a lot. |
In that case all of the exceptions should be behind interfaces, though that is rather... annoying. |
You can catch Interfaces, that the same.
And that way more useful, than a PHPdoc Most of the biggest PHP works with interfaces. |
My point being biggest frameworks use separate interfaces for specific error types, not a generic one. |
Nice PR,, hope it gets approved soon. |
92766fe
to
73012a9
Compare
73012a9
to
feb76b3
Compare
Hi @gehrisandro, would it be possible to have some feedback on this PR ? The Thanks a lot. |
What:
Description:
HI @gehrisandro @nunomaduro, I recently used this library and got an API exception in production. Currently there is no
@throws
phpdoc above method to help the developer to be aware exception are thrown and which can be caught.@throws
annotation allow tools like PHPStorm or PHPStan to report not caught exception. I tried to improve the documentation then.OpenAIThrowable
interface which allow to catch all of them.@throws OpenAIThrowable
to every method throwing an exception@throws
tag: https://phpstan.org/blog/bring-your-exceptions-under-control$response->getBody()->getContents();
throw a RuntimeException, I introduced aUnreadableResponse
exception to encapsulate the default exception (and implementsOpenAIThrowable
).Thanks.
Related: