fix(core): handle optional response fields from code assist API#20345
fix(core): handle optional response fields from code assist API#20345
Conversation
Summary of ChangesHello @sehoon38, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the resilience of the system by making various fields in the Code Assist API responses optional. This change prevents potential runtime errors when expected data is absent, ensuring that the application can gracefully handle incomplete responses. It also introduces default values and logging for critical user tier information, improving the overall stability and diagnostic capabilities of the Code Assist integration. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses the potential for missing fields in the Code Assist API responses by making several type definitions optional and implementing robust fallbacks. The changes in types.ts, converter.ts, and setup.ts work together to handle optional tier IDs and other response data gracefully, defaulting to the STANDARD tier and logging warnings where appropriate. The updates in usePrivacySettings.ts also correctly handle optional boolean values. The overall implementation is solid and significantly improves the client's resilience to API variations. I have not found any issues of high or critical severity.
|
Size Change: +1.03 kB (0%) Total Size: 25.7 MB
ℹ️ View Unchanged
|
Summary
This PR makes several fields within the Code Assist API responses optional and ensures the system handles these cases gracefully. Specifically, it updates the type definitions in
packages/core/src/code_assist/types.tsandconverter.tsto reflect the possibility of missing data (e.g.,id,name,candidates,totalTokens) and provides robust fallbacks insetup.tswhen tier IDs are missing.Details
CaGenerateContentResponse,VertexGenerateContentResponse, andCaCountTokenResponseinconverter.tsto make properties optional and provide safe fallbacks.GeminiUserTier,IneligibleTier,PrivacyNotice,LongRunningOperationResponse,OnboardUserResponse, andCodeAssistGlobalUserSettingResponseintypes.tsto make their respective properties optional.setup.tsto log warnings when the user tier ID is not returned from the Code Assist API (loadCodeAssistoronboardUser) and defaults to theSTANDARDtier securely.Related Issues
Fixes #20187
How to Validate
npm run testnpm run typecheckSTANDARDif a mocked API response is provided without tier IDs.Pre-Merge Checklist