fix(cli): suppress unhandled AbortError logs during request cancellation (#22621)

This commit is contained in:
euxaristia
2026-04-09 14:27:08 -04:00
committed by GitHub
parent 0690192d45
commit a9b5c693ca
2 changed files with 27 additions and 0 deletions

View File

@@ -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')

View File

@@ -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!