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 a new VertexAI error type #8240
base: master
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: d71e71d The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Size Report 1Affected Products
Test Logs |
Size Analysis Report 1Affected Products
Test Logs |
7594331
to
5fb071b
Compare
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.
I know this looks like a lot of comments but the core of this PR was pretty solid, it's a big rewrite of the whole error architecture, thanks for putting in all the work investigating and trying different approaches.
packages/vertexai/src/types/error.ts
Outdated
* | ||
* @public | ||
*/ | ||
export class VertexAIError extends FirebaseError { |
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.
We shouldn't have any code in types
- for style purposes and it also causes some obscure bugs during build sometimes. Let's move this to src/errors.ts
.
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.
We still want users to be able to import VertexAIError
, so I moved the class implementation to src/errors.ts
, but am still exporting it from types
. Does this approach still cause some bugs during build times?
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.
Can't we export it out of api.ts or index.ts? I guess I'd prefer api.ts since there's a few class exports there already.
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.
We don't currently export any classes from api.ts
- we only have getVertexAI()
, and getGenerativeModel()
. I feel like it's a bit odd to export an error alongside those. Could we add export './errors'
to index.ts
?
packages/vertexai/src/types/error.ts
Outdated
* @param errorDetails - Optional additional details about the error. | ||
*/ | ||
constructor( | ||
readonly code: VertexAIErrorCode, |
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.
Realized the constructor is already kind of long and only going to get longer as we think of more properties to add. (We already have to add "response" as mentioned in another comment.) Maybe we can put all the optional properties into an object, so it's constructor(code, message, customErrorData)
where customErrorData
is an object with all the optional properties.
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.
Agreed! since status
, statusText
, and errorDetails
are used only when throwing on HTTP responses, I moved them into a HTTPErrorDetails
interface, and accept that as a parameter instead.
New constructor:
constructor(
readonly code: VertexAIErrorCode,
readonly message: string,
readonly httpErrorDetails?: HTTPErrorDetails,
readonly generateContentResponse?: GenerateContentResponse
)
New error declaration with http details:
throw new VertexAIError(
VertexAIErrorCode.FETCH_ERROR,
`Error fetching from ${url}: [${response.status} ${response.statusText}] ${message}`,
{
status: response.status,
statusText: response.statusText,
errorDetails
}
);
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.
I think we should future proof it by making it not HTTPError specific. We might put other details in here in the future not related to HTTP, I don't think we should then create a separate arg for that. I think response should go in here too.
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.
Sounds good! I renamed httpErrorData
to customErrorData
, made all the properties optional, and moved generateContentResponse
into it.
Since we're making all these properties optional and we expect to add more in the future, I am a little worried our error declarations will start looking like this:
throw new VertexAIError(
VertexAIErrorCode.FETCH_ERROR,
`Error fetching from ${url}: [${response.status} ${response.statusText}] ${message}`,
{
undefined, // unused `status`. must be undefined to "skip over" to the field we want to include
undefined, // unused `statusText`
undefined, // unused `response`
undefined, // unused `customErrorData`
newErrorField
}
);
3b4301a
to
c3a3037
Compare
VertexAIError
so that users caninstanceof
the errors from the VertexAI SDK.status
,statusText
,errorDetails
) (mirroring google-gemini/generative-ai-js@111e970)ErrorFactory
towards our new error typeVertexAIErrorCode.ERROR
to align with the generic error in the Google AI SDKGoogleGenerativeAIError
Testing
I tested this in a React application in Chrome and Safari, and in a Node project.
instanceof
and the stack trace works in these environments.Error output in different environments
Safari
Chrome
Node