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()
: null;
let errorToHandle: unknown | undefined;
try {
consolePatcher.patch();
coreEvents.on(CoreEvent.UserFeedback, handleUserFeedback);
@@ -213,6 +214,8 @@ export async function runNonInteractive(
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) {
handleError(error, config);
errorToHandle = error;
} finally {
consolePatcher.cleanup();
coreEvents.off(CoreEvent.UserFeedback, handleUserFeedback);
@@ -310,5 +313,9 @@ export async function runNonInteractive(
await shutdownTelemetry(config);
}
}
if (errorToHandle) {
handleError(errorToHandle, config);
}
});
}