Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Feb 10, 2026

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: Added HandleAiSdkErrorOptions interface with onError (telemetry callback) and formatMessage (i18n formatter) hooks. The third parameter is fully optional — existing callers are unaffected.
  • src/api/providers/gemini.ts: Replaced manual ApiProviderError + TelemetryService + t() catch blocks in createMessage and completePrompt with handleAiSdkError(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.

  • Behavior:
    • Refactor handleAiSdkError() in ai-sdk.ts to include optional onError and formatMessage hooks for telemetry and i18n.
    • Migrate error handling in createMessage and completePrompt in gemini.ts and vertex.ts to use handleAiSdkError().
  • Tests:
    • Add tests for handleAiSdkError() in ai-sdk.spec.ts to verify onError and formatMessage functionality.
  • Misc:
    • All 23 AI SDK providers now use handleAiSdkError() for error handling.

This description was created by Ellipsis for 265c24c. You can customize this summary. It will automatically update as commits are pushed.

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.
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 10, 2026
@roomote
Copy link
Contributor

roomote bot commented Feb 10, 2026

Rooviewer Clock   See task

Clean refactor. All issues resolved.

  • Add test coverage for the new HandleAiSdkErrorOptions (onError and formatMessage callbacks) in ai-sdk.spec.ts
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Comment on lines +743 to +766
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
}
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant