Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/api/providers/__tests__/gemini.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ describe("GeminiHandler", () => {
modelId: GEMINI_MODEL_NAME,
operation: "createMessage",
}),
// Verify diagnostic properties are included
expect.objectContaining({
messageCount: expect.any(Number),
geminiContentsCount: expect.any(Number),
hasToolUseBlocks: expect.any(Boolean),
hasToolResultBlocks: expect.any(Boolean),
hasImageBlocks: expect.any(Boolean),
emptyPartsCount: expect.any(Number),
toolIdToNameSize: expect.any(Number),
hasThinkingConfig: expect.any(Boolean),
usingNativeTools: expect.any(Boolean),
includeThoughtSignatures: expect.any(Boolean),
}),
)

// Verify it's an ApiProviderError
Expand Down
31 changes: 30 additions & 1 deletion src/api/providers/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,36 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error)
const apiError = new ApiProviderError(errorMessage, this.providerName, model, "createMessage")
TelemetryService.instance.captureException(apiError)

// Add request diagnostics to help debug INVALID_ARGUMENT errors
TelemetryService.instance.captureException(apiError, {
// Message structure diagnostics
messageCount: messages.length,
geminiContentsCount: contents.length,

// Content type diagnostics
hasToolUseBlocks: messages.some(
(m) => Array.isArray(m.content) && m.content.some((b: { type: string }) => b.type === "tool_use"),
),
hasToolResultBlocks: messages.some(
(m) =>
Array.isArray(m.content) && m.content.some((b: { type: string }) => b.type === "tool_result"),
),
hasImageBlocks: messages.some(
(m) => Array.isArray(m.content) && m.content.some((b: { type: string }) => b.type === "image"),
),

// Conversion diagnostics - check for empty parts which cause INVALID_ARGUMENT
emptyPartsCount: contents.filter((c) => !c.parts || c.parts.length === 0).length,

// Tool mapping diagnostics - incomplete mapping causes conversion errors
toolIdToNameSize: toolIdToName.size,

// Configuration that might affect the request
hasThinkingConfig: Boolean(thinkingConfig),
usingNativeTools,
includeThoughtSignatures,
})

if (error instanceof Error) {
throw new Error(t("common:errors.gemini.generate_stream", { error: error.message }))
Expand Down
Loading