-
Notifications
You must be signed in to change notification settings - Fork 2.9k
refactor: unify Gemini/Vertex error handling via handleAiSdkError() #11364
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
Enrich handleAiSdkError() with optional HandleAiSdkErrorOptions to support telemetry capture and i18n message formatting without adding dependencies to the shared transform layer. Migrate gemini.ts and vertex.ts outer catch blocks (createMessage and completePrompt) from bespoke ApiProviderError + i18n patterns to the shared handleAiSdkError() with onError and formatMessage callbacks. All 23 migrated AI SDK providers now use handleAiSdkError() for their outer error path.
Clean refactor. All issues resolved.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| export interface HandleAiSdkErrorOptions { | ||
| /** | ||
| * Called with the extracted error message and the original error before | ||
| * throwing. Use this to report to telemetry or structured logging. | ||
| * | ||
| * @example | ||
| * onError: (msg) => { | ||
| * TelemetryService.instance.captureException( | ||
| * new ApiProviderError(msg, providerName, modelId, "createMessage"), | ||
| * ) | ||
| * } | ||
| */ | ||
| onError?: (message: string, originalError: unknown) => void | ||
|
|
||
| /** | ||
| * Custom message formatter. When provided, the returned string is used | ||
| * as the thrown Error's message instead of the default | ||
| * `${providerName}: ${extractedMessage}` format. | ||
| * | ||
| * @example | ||
| * formatMessage: (msg) => t("common:errors.gemini.generate_stream", { error: msg }) | ||
| */ | ||
| formatMessage?: (message: string) => string | ||
| } |
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.
The existing handleAiSdkError tests (lines 869-911) only cover the two-parameter signature. The new onError and formatMessage options have no test coverage. Worth adding a few cases to verify: (1) onError is called with the extracted message and original error, (2) formatMessage overrides the default ${providerName}: ${message} format, and (3) when neither option is provided, existing behavior is unchanged (already covered, but a combined test with both options would round things out).
Fix it with Roo Code or mention @roomote and request a fix.
Addresses review feedback — adds 4 tests: - onError callback receives extracted message and original error - formatMessage overrides default message format - combined onError + formatMessage with status preservation - default format unchanged when no options provided
Summary
Standardizes error handling across all migrated AI SDK providers by enriching
handleAiSdkError()with optional telemetry and i18n support, then migrating Gemini and Vertex to use it. These were the last two providers with bespoke outer-catch patterns.Changes
src/api/transform/ai-sdk.ts: AddedHandleAiSdkErrorOptionsinterface withonError(telemetry callback) andformatMessage(i18n formatter) hooks. The third parameter is fully optional — existing callers are unaffected.src/api/providers/gemini.ts: Replaced manualApiProviderError+TelemetryService+t()catch blocks increateMessageandcompletePromptwithhandleAiSdkError(error, providerName, { onError, formatMessage }).src/api/providers/vertex.ts: Same migration as Gemini.All 23 migrated AI SDK providers now use
handleAiSdkError()for their outer error path.Important
Refactor error handling in Gemini and Vertex providers to use
handleAiSdkError()with optional telemetry and i18n support.handleAiSdkError()inai-sdk.tsto include optionalonErrorandformatMessagehooks for telemetry and i18n.createMessageandcompletePromptingemini.tsandvertex.tsto usehandleAiSdkError().handleAiSdkError()inai-sdk.spec.tsto verifyonErrorandformatMessagefunctionality.handleAiSdkError()for error handling.This description was created by
for 265c24c. You can customize this summary. It will automatically update as commits are pushed.