fix: improve error message when OAuth succeeds but project ID is required#21070
Conversation
…ired Fixes google-gemini#15749 The issue was that OAuth authentication would succeed (showing 'Authentication succeeded'), but then setupUser would throw ProjectIdRequiredError, which was caught and displayed as 'Failed to login. Message: ...'. This was confusing because authentication had actually succeeded. Now ProjectIdRequiredError is caught specifically and the error message is shown directly without the 'Failed to login' prefix, making it clear that OAuth succeeded but account setup requires GOOGLE_CLOUD_PROJECT to be set.
Summary of ChangesHello, 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 significantly improves the clarity of authentication error messages within the CLI. It addresses a specific scenario where a user successfully authenticates via OAuth but their account configuration still requires a Google Cloud project ID. By catching and displaying the 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 addresses a confusing error message by specifically handling ProjectIdRequiredError in three separate authentication flows. The changes ensure that when OAuth succeeds but a project ID is missing, the user sees a clear message about the missing configuration instead of a misleading 'Failed to login' error. The implementation is correct and is well-supported by new unit tests for each modified code path. I have one suggestion to improve consistency in error message handling.
Summary
Fixes confusing error message when OAuth authentication succeeds but account setup requires
GOOGLE_CLOUD_PROJECT. The error message now correctly reflects that OAuth succeeded but account configuration requires a project ID, removing the misleading "Failed to login" prefix.Details
When authenticating with a workspace Google account that requires
GOOGLE_CLOUD_PROJECT, the OAuth flow succeeds (showing "Authentication succeeded"), but thensetupUser()throwsProjectIdRequiredErrorif the project ID is not set. Previously, this error was caught and displayed with a "Failed to login. Message:" prefix, which was confusing since OAuth had already succeeded.This PR:
ProjectIdRequiredErrorspecifically in all three authentication error handling pathsError handling paths updated:
performInitialAuth()- Initial authentication during startupuseAuthCommand()- Authentication hook in UIhandleAuthSelect()- Auth selection handler in AppContainerRelated Issues
Fixes #15749
How to Validate
Test with workspace account requiring project ID:
Select "Login with Google" and authenticate with a workspace account
Expected behavior:
This account requires setting the GOOGLE_CLOUD_PROJECT or GOOGLE_CLOUD_PROJECT_ID env var. See https://goo.gle/gemini-cli-auth-docs#workspace-gcaVerify tests pass:
npm test -- packages/cli/src/core/auth.test.ts packages/cli/src/ui/auth/useAuth.test.tsxPre-Merge Checklist