mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-12 15:10:59 -07:00
fix(auth): don't crash when initial auth fails (#17308)
This commit is contained in:
@@ -1135,6 +1135,8 @@ describe('gemini.tsx main function exit codes', () => {
|
|||||||
vi.mocked(loadSandboxConfig).mockResolvedValue({} as any);
|
vi.mocked(loadSandboxConfig).mockResolvedValue({} as any);
|
||||||
vi.mocked(loadCliConfig).mockResolvedValue({
|
vi.mocked(loadCliConfig).mockResolvedValue({
|
||||||
refreshAuth: vi.fn().mockRejectedValue(new Error('Auth failed')),
|
refreshAuth: vi.fn().mockRejectedValue(new Error('Auth failed')),
|
||||||
|
getRemoteAdminSettings: vi.fn().mockReturnValue(undefined),
|
||||||
|
isInteractive: vi.fn().mockReturnValue(true),
|
||||||
} as unknown as Config);
|
} as unknown as Config);
|
||||||
vi.mocked(loadSettings).mockReturnValue(
|
vi.mocked(loadSettings).mockReturnValue(
|
||||||
createMockSettings({
|
createMockSettings({
|
||||||
|
|||||||
@@ -373,6 +373,7 @@ export async function main() {
|
|||||||
// Refresh auth to fetch remote admin settings from CCPA and before entering
|
// Refresh auth to fetch remote admin settings from CCPA and before entering
|
||||||
// the sandbox because the sandbox will interfere with the Oauth2 web
|
// the sandbox because the sandbox will interfere with the Oauth2 web
|
||||||
// redirect.
|
// redirect.
|
||||||
|
let initialAuthFailed = false;
|
||||||
if (!settings.merged.security.auth.useExternal) {
|
if (!settings.merged.security.auth.useExternal) {
|
||||||
try {
|
try {
|
||||||
if (
|
if (
|
||||||
@@ -400,8 +401,7 @@ export async function main() {
|
|||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
debugLogger.error('Error authenticating:', err);
|
debugLogger.error('Error authenticating:', err);
|
||||||
await runExitCleanup();
|
initialAuthFailed = true;
|
||||||
process.exit(ExitCodes.FATAL_AUTHENTICATION_ERROR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,6 +427,10 @@ export async function main() {
|
|||||||
// another way to decouple refreshAuth from requiring a config.
|
// another way to decouple refreshAuth from requiring a config.
|
||||||
|
|
||||||
if (sandboxConfig) {
|
if (sandboxConfig) {
|
||||||
|
if (initialAuthFailed) {
|
||||||
|
await runExitCleanup();
|
||||||
|
process.exit(ExitCodes.FATAL_AUTHENTICATION_ERROR);
|
||||||
|
}
|
||||||
let stdinData = '';
|
let stdinData = '';
|
||||||
if (!process.stdin.isTTY) {
|
if (!process.stdin.isTTY) {
|
||||||
stdinData = await readStdin();
|
stdinData = await readStdin();
|
||||||
|
|||||||
Reference in New Issue
Block a user