fix(byok): improve Gemini provider error handling and add tests#2686
Merged
dmitrivMS merged 3 commits intomicrosoft:mainfrom Jan 6, 2026
Merged
fix(byok): improve Gemini provider error handling and add tests#2686dmitrivMS merged 3 commits intomicrosoft:mainfrom
dmitrivMS merged 3 commits intomicrosoft:mainfrom
Conversation
Contributor
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
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>toPromise<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 |
Contributor
|
Hi @bharatvansh, Can you resolve the conflicts? |
fa5f7fc to
4bb6c73
Compare
Contributor
Author
|
@vijayupadya I have resolved the conflicts, You should be able to marge it now. |
4bb6c73 to
079a657
Compare
vijayupadya
approved these changes
Jan 5, 2026
dmitrivMS
approved these changes
Jan 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Promise<any>toPromise<void>Testing
npx vitest run src/extension/byok/vscode-node/test/geminiNativeProvider.spec.ts- all 3 tests pass