Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/cli/src/gemini.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/gemini.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,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!
Expand Down
Loading