Skip to content

Commit faff4c1

Browse files
fix(vscode-lm): surface the shared canonical abort for host cancellation
Human review follow-up: replace the remaining hand-built AbortError for a host CancellationError with createAbortError(this.providerName); update the two assertions that pinned the old branded message to the canonical text. vscode-lm.spec.ts 383 passed; tsc clean.
1 parent 26cfd61 commit faff4c1

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

‎src/api/providers/__tests__/vscode-lm.spec.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,10 +1009,10 @@ describe("VsCodeLmHandler", () => {
10091009
tools: salvageTools,
10101010
})
10111011

1012-
// The series normalizes host cancellation to a canonical AbortError
1013-
// (name "AbortError", same branded message), so assert the message
1014-
// only - an Error-instance comparison would also pin the name.
1015-
await expect(stream.next()).rejects.toThrow("Zoo Code <Language Model API>: Request cancelled by user")
1012+
// The series normalizes host cancellation to the shared canonical AbortError
1013+
// (name "AbortError"), so assert the message only - an Error-instance
1014+
// comparison would also pin the name.
1015+
await expect(stream.next()).rejects.toThrow("The VS Code LM request was aborted")
10161016
await expect(stream.next()).resolves.toEqual({ done: true, value: undefined })
10171017
})
10181018

@@ -2706,7 +2706,7 @@ describe("VsCodeLmHandler", () => {
27062706
)
27072707
})
27082708

2709-
it("should throw a Zoo Code branded error when request is cancelled", async () => {
2709+
it("should throw the shared canonical abort when request is cancelled", async () => {
27102710
const systemPrompt = "You are a helpful assistant"
27112711
const messages: Anthropic.Messages.MessageParam[] = [
27122712
{
@@ -2717,8 +2717,11 @@ describe("VsCodeLmHandler", () => {
27172717

27182718
mockLanguageModelChat.sendRequest.mockRejectedValueOnce(new vscode.CancellationError())
27192719

2720-
await expect(handler.createMessage(systemPrompt, messages).next()).rejects.toThrow(
2721-
"Zoo Code <Language Model API>: Request cancelled by user",
2720+
await expect(handler.createMessage(systemPrompt, messages).next()).rejects.toSatisfy(
2721+
(error) =>
2722+
error instanceof Error &&
2723+
error.name === "AbortError" &&
2724+
error.message === "The VS Code LM request was aborted",
27222725
)
27232726
})
27242727

@@ -3081,7 +3084,7 @@ describe("VsCodeLmHandler", () => {
30813084
(error) =>
30823085
error instanceof Error &&
30833086
error.name === "AbortError" &&
3084-
error.message === "Zoo Code <Language Model API>: Request cancelled by user",
3087+
error.message === "The VS Code LM request was aborted",
30853088
)
30863089
})
30873090

‎src/api/providers/vscode-lm.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,10 +1533,9 @@ export class VsCodeLmHandler extends BaseProvider implements SingleCompletionHan
15331533
if (error instanceof vscode.CancellationError) {
15341534
// The host rejected because the request was cancelled: either the
15351535
// bridged external signal aborted or the user cancelled the request
1536-
// in VS Code. Both are aborts, so surface a standard abort error.
1537-
const abortError = new Error("Zoo Code <Language Model API>: Request cancelled by user")
1538-
abortError.name = "AbortError"
1539-
throw abortError
1536+
// in VS Code. Both are aborts, so surface the shared canonical error
1537+
// instead of a hand-built copy.
1538+
throw createAbortError(this.providerName)
15401539
}
15411540

15421541
if (error instanceof Error) {

0 commit comments

Comments
 (0)