Skip to content

Commit 2a8e1a8

Browse files
fix(patch): cherry-pick 87a0db2 to release/v0.25.0-pr-17308 [CONFLICTS] (#17316)
Co-authored-by: Shreya Keshive <shreyakeshive@google.com>
1 parent c9dbf70 commit 2a8e1a8

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
@@ -1065,6 +1065,8 @@ describe('gemini.tsx main function exit codes', () => {
10651065
vi.mocked(loadSandboxConfig).mockResolvedValue({} as any);
10661066
vi.mocked(loadCliConfig).mockResolvedValue({
10671067
refreshAuth: vi.fn().mockRejectedValue(new Error('Auth failed')),
1068+
getRemoteAdminSettings: vi.fn().mockReturnValue(undefined),
1069+
isInteractive: vi.fn().mockReturnValue(true),
10681070
} as unknown as Config);
10691071
vi.mocked(loadSettings).mockReturnValue({
10701072
merged: {

packages/cli/src/gemini.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ export async function main() {
363363
// Refresh auth to fetch remote admin settings from CCPA and before entering
364364
// the sandbox because the sandbox will interfere with the Oauth2 web
365365
// redirect.
366+
let initialAuthFailed = false;
366367
if (
367368
settings.merged.security?.auth?.selectedType &&
368369
!settings.merged.security?.auth?.useExternal
@@ -390,8 +391,7 @@ export async function main() {
390391
}
391392
} catch (err) {
392393
debugLogger.error('Error authenticating:', err);
393-
await runExitCleanup();
394-
process.exit(ExitCodes.FATAL_AUTHENTICATION_ERROR);
394+
initialAuthFailed = true;
395395
}
396396
}
397397

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

416416
if (sandboxConfig) {
417+
if (initialAuthFailed) {
418+
await runExitCleanup();
419+
process.exit(ExitCodes.FATAL_AUTHENTICATION_ERROR);
420+
}
417421
let stdinData = '';
418422
if (!process.stdin.isTTY) {
419423
stdinData = await readStdin();

0 commit comments

Comments
 (0)