-
-
Notifications
You must be signed in to change notification settings - Fork 590
Introduce OpenAIThrowable #429
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
base: main
Are you sure you want to change the base?
Conversation
7ad8627
to
d0a3770
Compare
Friendly ping @nunomaduro @gehrisandro, Is something missing for a review ? Thanks |
I agree that this is a useful and beneficial improvement. I see no reason why this cannot be merged @nunomaduro |
Anyway to move forward this PR @gehrisandro @nunomaduro ? Thanks a lot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for delay. I took a look at this and outside of the linting failing - I'm not really following this implementation.
- It appears to introduce a custom interface (OpenAIThrowable) that extends Throwable
- All classes then implement that interface.
Could you give any background to help me learn why you took that route instead of say like a base class of like OpenAiException that all these others extended from, which then extended Exception.
It seems like on a face value there is just a bit of workarounds here to avoid this callout.
PHP classes cannot implement the Throwable interface directly, and must instead extend Exception.
I want to be sure I'm understanding any trade-offs properly.
Hi @iBotPeaches, thanks for your review. My main goal is
I mostly saw in such situation the following strategy:
Introducing an Interface offers more flexibility because I can write
For instance, and would allow to
Notice I can also implements multiple interfaces when I cannot extends multiple classes. So it offer more flexibility. But I know some repository prefer to introduce a BaseException (or used this strategy because it was introduced before the Throwable interface exists in PHP). If it's the preferred choice from OpenAI, I won't go against it if it the preferred choice. #287 didn't get any review in 2 years and this PR is waiting for 1 year so I'd like to move on this in order to "fix" the phpdoc and adding the |
d0a3770
to
71a3621
Compare
@iBotPeaches I rebased so you can approval the workflow run. Also I'll wait for your decision if you prefer a baseException or an Interface |
I kicked off the workflows and I don't have a strong opinion on base vs interface. Let me do some research though to double check if I'm missing anything. |
I took a look at your game plan and have a few thoughts I'm looking for clarity on.
I wanted to give this PR the time it deserved after waiting a solid few years, but with the bugs and missing parity with new OpenAI APIs - unfortunately at the moment re-hauling the exceptions/throws which can have a direct impact on strict tooling for user-land code does not seem like something I should focus at the moment. |
It was made to catch
If we introduce an interface or a baseException, to allows people catching it rather than
people will still need to be aware of the implementation of OpenAIThrowable, cause it might throw a So instead it's recommended to throw a Domain-related Exception.
"I'm sure a", is it missing the end of the sentence @iBotPeaches ?
If you prefer I can add specific But if you prefer having
almost everywhere rather than |
They're very different things catching |
hmm lol. Not sure what thought I had going there. Removed it |
But are you sure it's really true ? When looking at the interface it currently say that the mehtod only throw ErrorException, which is indeed a subset of
But when looking at the implementation,
and this method is throwing TransporterException , then throwIfJsonError is called
and this method does throw ErrorException or UnserializableResponse .
So
Throwing an Interface/BaseException is also a way to simplify the maintenance of what is exactly thrown.
|
If preferred @iBotPeaches, I can open a PR with just all the |
At moment - no need @VincentLanglet. I am supposed to start small as a collaborator and touching ~30 files with throws when this PR wasn't really visited by the other maintainers. I want to start smaller before tackling exceptions. |
Am I missing something? The PR changes 6 files and effects no one from a BC perspective, it literally just adds an interface. The primary sticking point seems to be interface vs base class, and I don't think there's a particularly hard opinion either way. |
I guess my confidence is the only thing. For all the other PRs thus far I can sit down and replicate a bug / test a feature. Here I am traveling through more of a design pattern than a bug/feature in my understanding. Thus with a discussion of patterns (throwable/exception) and preference (interface/base exception) both which are a jumping point for further changes I wanted to type it out a bit to try and understand why this PR sat. |
What:
Description:
Hi @gehrisandro
I'm trying to move #287 forward by splitting it in 3 smaller PRs:
The purpose of this PR is to provide an easy way to try/catch method of this lib:
\Exception
which catch everythingOpenAI\Exceptions\ErrorException|OpenAI\Exceptions\InvalidArgumentException|...
which is complicated and can miss an exception if a new one is introduced later.Related:
#287