-
Notifications
You must be signed in to change notification settings - Fork 10.7k
fix(patch): cherry-pick 9e6914d to release/v0.22.0-preview.2-pr-15288 to patch version v0.22.0-preview.2 and create version 0.22.0-preview.3 #15294
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,8 @@ import type { | |
| import { parseGoogleApiError } from './googleErrors.js'; | ||
| import { getErrorStatus, ModelNotFoundError } from './httpErrors.js'; | ||
|
|
||
| const DEFAULT_RETRYABLE_DELAY_SECOND = 5; | ||
|
|
||
| /** | ||
| * A non-retryable error indicating a hard quota limit has been reached (e.g., daily limit). | ||
| */ | ||
|
|
@@ -112,6 +114,18 @@ export function classifyGoogleError(error: unknown): unknown { | |
| retryDelaySeconds, | ||
| ); | ||
| } | ||
| } else if (status === 429) { | ||
| // Fallback: If it is a 429 but doesn't have a specific "retry in" message, | ||
| // assume it is a temporary rate limit and retry after 5 sec (same as DEFAULT_RETRY_OPTIONS). | ||
| return new RetryableQuotaError( | ||
| errorMessage, | ||
| googleApiError ?? { | ||
| code: 429, | ||
| message: errorMessage, | ||
| details: [], | ||
| }, | ||
| DEFAULT_RETRYABLE_DELAY_SECOND, | ||
| ); | ||
| } | ||
|
|
||
| return error; // Not a 429 error we can handle with structured details or a parsable retry message. | ||
|
|
@@ -232,5 +246,21 @@ export function classifyGoogleError(error: unknown): unknown { | |
| ); | ||
| } | ||
| } | ||
|
|
||
| // If we reached this point and the status is still 429, we return retryable. | ||
| if (status === 429) { | ||
| const errorMessage = | ||
| googleApiError?.message || | ||
| (error instanceof Error ? error.message : String(error)); | ||
| return new RetryableQuotaError( | ||
| errorMessage, | ||
| googleApiError ?? { | ||
| code: 429, | ||
| message: errorMessage, | ||
| details: [], | ||
| }, | ||
| DEFAULT_RETRYABLE_DELAY_SECOND, | ||
| ); | ||
| } | ||
|
Comment on lines
+251
to
+264
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block of code, which creates a fallback To improve maintainability, I recommend extracting this logic into a single, private helper function. This function would be responsible for creating the default For example: function createDefaultRetryableError(error: unknown, googleApiError: GoogleApiError | null): RetryableQuotaError {
const errorMessage =
googleApiError?.message ||
(error instanceof Error ? error.message : String(error));
return new RetryableQuotaError(
errorMessage,
googleApiError ?? {
code: 429,
message: errorMessage,
details: [],
},
DEFAULT_RETRYABLE_DELAY_SECOND,
);
}This would centralize the fallback logic, making the code cleaner and easier to manage. |
||
| return error; // Fallback to original error if no specific classification fits. | ||
| } | ||
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.
In this test case, the variable
errorWithEmptyDetailsis used, but the error object it holds actually contains details (lines 432-441). This name is misleading and was likely copied from the previous test. Using a more accurate name likeerrorWithSomeDetailswould improve the test's readability and prevent future confusion.