fix(cli): re-throw errors in non-interactive mode (#11849)

This commit is contained in:
Sandy Tao
2025-10-23 18:52:16 -07:00
committed by GitHub
parent 0fe82a2f4e
commit 884d838a1e

View File

@@ -71,6 +71,7 @@ export async function runNonInteractive(
? new StreamJsonFormatter() ? new StreamJsonFormatter()
: null; : null;
let errorToHandle: unknown | undefined;
try { try {
consolePatcher.patch(); consolePatcher.patch();
coreEvents.on(CoreEvent.UserFeedback, handleUserFeedback); coreEvents.on(CoreEvent.UserFeedback, handleUserFeedback);
@@ -213,6 +214,8 @@ export async function runNonInteractive(
message: 'Maximum session turns exceeded', message: 'Maximum session turns exceeded',
}); });
} }
} else if (event.type === GeminiEventType.Error) {
throw event.value.error;
} }
} }
@@ -302,7 +305,7 @@ export async function runNonInteractive(
} }
} }
} catch (error) { } catch (error) {
handleError(error, config); errorToHandle = error;
} finally { } finally {
consolePatcher.cleanup(); consolePatcher.cleanup();
coreEvents.off(CoreEvent.UserFeedback, handleUserFeedback); coreEvents.off(CoreEvent.UserFeedback, handleUserFeedback);
@@ -310,5 +313,9 @@ export async function runNonInteractive(
await shutdownTelemetry(config); await shutdownTelemetry(config);
} }
} }
if (errorToHandle) {
handleError(errorToHandle, config);
}
}); });
} }