mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 14:10:37 -07:00
fix(core): handle AbortError thrown during processTurn (#21296)
Co-authored-by: Gaurav <39389231+gsquared94@users.noreply.github.com>
This commit is contained in:
@@ -728,6 +728,23 @@ describe('Gemini Client (client.ts)', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('yields UserCancelled when processTurn throws AbortError', async () => {
|
||||
const abortError = new Error('Aborted');
|
||||
abortError.name = 'AbortError';
|
||||
vi.spyOn(client['loopDetector'], 'turnStarted').mockRejectedValueOnce(
|
||||
abortError,
|
||||
);
|
||||
|
||||
const stream = client.sendMessageStream(
|
||||
[{ text: 'Hi' }],
|
||||
new AbortController().signal,
|
||||
'prompt-id-abort-error',
|
||||
);
|
||||
const events = await fromAsync(stream);
|
||||
|
||||
expect(events).toEqual([{ type: GeminiEventType.UserCancelled }]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
compressionStatus:
|
||||
|
||||
@@ -34,7 +34,7 @@ import {
|
||||
type RetryAvailabilityContext,
|
||||
} from '../utils/retry.js';
|
||||
import type { ValidationRequiredError } from '../utils/googleQuotaErrors.js';
|
||||
import { getErrorMessage } from '../utils/errors.js';
|
||||
import { getErrorMessage, isAbortError } from '../utils/errors.js';
|
||||
import { tokenLimit } from './tokenLimits.js';
|
||||
import type {
|
||||
ChatRecordingService,
|
||||
@@ -957,6 +957,12 @@ export class GeminiClient {
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (signal?.aborted || isAbortError(error)) {
|
||||
yield { type: GeminiEventType.UserCancelled };
|
||||
return turn;
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
const hookState = this.hookStateMap.get(prompt_id);
|
||||
if (hookState) {
|
||||
|
||||
Reference in New Issue
Block a user