Skip to content

Commit 0fa9a54

Browse files
fix(patch): cherry-pick 87a0db2 to release/v0.26.0-preview.1-pr-17308 [CONFLICTS] (#17317)
Co-authored-by: Shreya Keshive <shreyakeshive@google.com>
1 parent 603e66b commit 0fa9a54

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

packages/cli/src/gemini.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,8 @@ describe('gemini.tsx main function exit codes', () => {
10851085
vi.mocked(loadSandboxConfig).mockResolvedValue({} as any);
10861086
vi.mocked(loadCliConfig).mockResolvedValue({
10871087
refreshAuth: vi.fn().mockRejectedValue(new Error('Auth failed')),
1088+
getRemoteAdminSettings: vi.fn().mockReturnValue(undefined),
1089+
isInteractive: vi.fn().mockReturnValue(true),
10881090
} as unknown as Config);
10891091
vi.mocked(loadSettings).mockReturnValue(
10901092
createMockSettings({

packages/cli/src/gemini.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ export async function main() {
373373
// Refresh auth to fetch remote admin settings from CCPA and before entering
374374
// the sandbox because the sandbox will interfere with the Oauth2 web
375375
// redirect.
376+
let initialAuthFailed = false;
376377
if (
377378
settings.merged.security.auth.selectedType &&
378379
!settings.merged.security.auth.useExternal
@@ -400,8 +401,7 @@ export async function main() {
400401
}
401402
} catch (err) {
402403
debugLogger.error('Error authenticating:', err);
403-
await runExitCleanup();
404-
process.exit(ExitCodes.FATAL_AUTHENTICATION_ERROR);
404+
initialAuthFailed = true;
405405
}
406406
}
407407

@@ -427,6 +427,10 @@ export async function main() {
427427
// another way to decouple refreshAuth from requiring a config.
428428

429429
if (sandboxConfig) {
430+
if (initialAuthFailed) {
431+
await runExitCleanup();
432+
process.exit(ExitCodes.FATAL_AUTHENTICATION_ERROR);
433+
}
430434
let stdinData = '';
431435
if (!process.stdin.isTTY) {
432436
stdinData = await readStdin();

0 commit comments

Comments
 (0)