Skip to content

Conversation

@bharatvansh
Copy link
Contributor

Summary

Improves error handling in GeminiNativeBYOKLMProvider by throwing clear, actionable errors instead of silently failing when no API key is configured.

Problem

Previously, when no API key was configured, provideLanguageModelChatResponse() would silently return without any feedback to the user. This made debugging difficult and left users confused about why Gemini wasn't working.

Changes

  • Error handling: provideLanguageModelChatResponse() and _makeRequest() now throw descriptive errors when API key is missing or client uninitialized
  • Client management: Added _ensureClient() to properly manage GoogleGenAI client lifecycle and avoid unnecessary recreation when the key hasn't changed
  • API key loading: Added _getOrReadApiKey() for lazy API key retrieval from storage
  • Type fix: Changed return type from Promise<any> to Promise<void>
  • Tests: Added unit tests covering:
    • Error thrown when no API key configured
    • Client initialization and streaming response
    • Client cleared when API key is deleted

Testing

  • npx vitest run src/extension/byok/vscode-node/test/geminiNativeProvider.spec.ts - all 3 tests pass
  • ✅ TypeScript compilation passes

@bharatvansh
Copy link
Contributor Author

@microsoft-github-policy-service agree

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves error handling in the Gemini BYOK provider by replacing silent failures with clear, actionable error messages when the API key is not configured. It also adds comprehensive unit tests to ensure the error handling works correctly.

Key changes:

  • Error Handling: Now throws descriptive errors instead of silently returning when no API key is configured
  • Client Lifecycle Management: Added methods to lazily load API keys and efficiently manage client creation
  • Type Safety: Changed return type from Promise<any> to Promise<void>
  • Test Coverage: Added 3 unit tests covering error cases, client initialization, and cleanup scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/extension/byok/vscode-node/geminiNativeProvider.ts Added _getOrReadApiKey() and _ensureClient() helper methods; improved error handling in provideLanguageModelChatResponse() and _makeRequest() to throw errors instead of silently returning; updated updateAPIKey() to properly manage client lifecycle
src/extension/byok/vscode-node/test/geminiNativeProvider.spec.ts Added new test file with mock implementations for @google/genai and helper functions; includes 3 test cases covering missing API key error, successful client initialization with streaming, and client cleanup on key deletion

@Tyriar Tyriar assigned vijayupadya and unassigned Tyriar Dec 29, 2025
@vijayupadya
Copy link
Contributor

Hi @bharatvansh, Can you resolve the conflicts?

@bharatvansh bharatvansh force-pushed the fix/gemini-byok-error-handling branch from fa5f7fc to 4bb6c73 Compare January 3, 2026 21:48
@bharatvansh
Copy link
Contributor Author

@vijayupadya I have resolved the conflicts, You should be able to marge it now.

@bharatvansh bharatvansh force-pushed the fix/gemini-byok-error-handling branch from 4bb6c73 to 079a657 Compare January 5, 2026 06:59
@vs-code-engineering vs-code-engineering bot added this to the December 2025 milestone Jan 5, 2026
@dmitrivMS dmitrivMS enabled auto-merge January 6, 2026 11:43
@dmitrivMS dmitrivMS added this pull request to the merge queue Jan 6, 2026
Merged via the queue into microsoft:main with commit dad0a99 Jan 6, 2026
9 checks passed
@bharatvansh bharatvansh deleted the fix/gemini-byok-error-handling branch January 6, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants