-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(byok): improve Gemini provider error handling and add tests #2686
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
fix(byok): improve Gemini provider error handling and add tests #2686
Conversation
|
@microsoft-github-policy-service agree |
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.
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 |
|
Hi @bharatvansh, Can you resolve the conflicts? |
fa5f7fc to
4bb6c73
Compare
|
@vijayupadya I have resolved the conflicts, You should be able to marge it now. |
4bb6c73 to
079a657
Compare
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