mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-16 08:10:46 -07:00
fix(cli): suppress unhandled AbortError logs during request cancellation (#22621)
This commit is contained in:
@@ -304,6 +304,25 @@ describe('gemini.tsx main function', () => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('should suppress AbortError and not open debug console', async () => {
|
||||
const debugLoggerErrorSpy = vi.spyOn(debugLogger, 'error');
|
||||
const debugLoggerLogSpy = vi.spyOn(debugLogger, 'log');
|
||||
const abortError = new DOMException(
|
||||
'The operation was aborted.',
|
||||
'AbortError',
|
||||
);
|
||||
|
||||
setupUnhandledRejectionHandler();
|
||||
process.emit('unhandledRejection', abortError, Promise.resolve());
|
||||
|
||||
await new Promise(process.nextTick);
|
||||
|
||||
expect(debugLoggerErrorSpy).not.toHaveBeenCalled();
|
||||
expect(debugLoggerLogSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Suppressed unhandled AbortError'),
|
||||
);
|
||||
});
|
||||
|
||||
it('should log unhandled promise rejections and open debug console on first error', async () => {
|
||||
const processExitSpy = vi
|
||||
.spyOn(process, 'exit')
|
||||
|
||||
@@ -164,6 +164,14 @@ export function getNodeMemoryArgs(isDebugMode: boolean): string[] {
|
||||
export function setupUnhandledRejectionHandler() {
|
||||
let unhandledRejectionOccurred = false;
|
||||
process.on('unhandledRejection', (reason, _promise) => {
|
||||
// AbortError is expected when the user cancels a request (e.g. pressing ESC).
|
||||
// It may surface as an unhandled rejection due to async timing in the
|
||||
// streaming pipeline, but it is not a bug.
|
||||
if (reason instanceof Error && reason.name === 'AbortError') {
|
||||
debugLogger.log(`Suppressed unhandled AbortError: ${reason.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const errorMessage = `=========================================
|
||||
This is an unexpected error. Please file a bug report using the /bug tool.
|
||||
CRITICAL: Unhandled Promise Rejection!
|
||||
|
||||
Reference in New Issue
Block a user