Skip to content

Commit 3b70688

Browse files
authored
Merge pull request microsoft#258225 from microsoft/tyriar/canceled
Differentiate unexpected exceptions from canceled errors
2 parents fd38dea + e0deab4 commit 3b70688

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/runInTerminalTool.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,12 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
320320

321321
const execution = new BackgroundTerminalExecution(toolTerminal.instance, xterm, command);
322322
RunInTerminalTool._backgroundExecutions.set(termId, execution);
323+
323324
outputAndIdle = await pollForOutputAndIdle(execution, false, token, this._languageModelsService);
325+
if (token.isCancellationRequested) {
326+
throw new CancellationError();
327+
}
328+
324329
if (!outputAndIdle.terminalExecutionIdleBeforeTimeout) {
325330
outputAndIdle = await racePollingOrPrompt(
326331
() => pollForOutputAndIdle(execution, true, token, this._languageModelsService),
@@ -330,6 +335,9 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
330335
this._languageModelsService,
331336
execution
332337
);
338+
if (token.isCancellationRequested) {
339+
throw new CancellationError();
340+
}
333341
}
334342

335343
let resultText = (
@@ -351,11 +359,11 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
351359
}]
352360
};
353361
} catch (e) {
354-
error = 'threw';
355362
if (termId) {
356363
RunInTerminalTool._backgroundExecutions.get(termId)?.dispose();
357364
RunInTerminalTool._backgroundExecutions.delete(termId);
358365
}
366+
error = e instanceof CancellationError ? 'canceled' : 'unexpectedException';
359367
throw e;
360368
} finally {
361369
store.dispose();
@@ -402,6 +410,10 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
402410
}
403411
this._logService.debug(`RunInTerminalTool: Using \`${strategy.type}\` execute strategy for command \`${command}\``);
404412
const executeResult = await strategy.execute(command, token);
413+
if (token.isCancellationRequested) {
414+
throw new CancellationError();
415+
}
416+
405417
this._logService.debug(`RunInTerminalTool: Finished \`${strategy.type}\` execute strategy with exitCode \`${executeResult.exitCode}\`, result.length \`${executeResult.output?.length}\`, error \`${executeResult.error}\``);
406418
outputLineCount = executeResult.output === undefined ? 0 : count(executeResult.output.trim(), '\n') + 1;
407419
exitCode = executeResult.exitCode;
@@ -419,7 +431,7 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
419431
} catch (e) {
420432
this._logService.debug(`RunInTerminalTool: Threw exception`);
421433
toolTerminal.instance.dispose();
422-
error = 'threw';
434+
error = e instanceof CancellationError ? 'canceled' : 'unexpectedException';
423435
throw e;
424436
} finally {
425437
store.dispose();

0 commit comments

Comments
 (0)