* refactor: unify AbortError detection with isAbortError utility
AbortError detection was scattered across 3+ patterns (string
comparison, .name check, .code check). Consolidates into a single
isAbortError() utility that handles all known patterns: "cancel"
string, DOMException, Error.name variants, ABORT_ERR code, and
plain objects. Updates call sites in core/llm/index.ts and
core/llm/utils/retry.ts.
* fix: use exact match for AbortError name, add null guard, improve tests
- Changed .includes("AbortError") to === "AbortError" to preserve
original exact-match semantics at L505 and retry.ts call sites
- Added null/undefined early return to prevent TypeError on
"name" in null
- Unified DOMException branch to use exact match consistently
- Tests: removed 4 redundant same-branch duplicates, added 12 new
cases (case sensitivity, empty string, non-string name, partial
name boundary, DOMException negative, plain object code asymmetry,
boolean, frozen object, Error subclass, TypeError)
- Fixed DOMException test skip from expect(true).toBe(true) to
it.skipIf
* fix: replace == null with === null || === undefined (eqeqeq)
---------
Co-authored-by: amabito <192487536+amabito@users.noreply.github.com>
Co-authored-by: amabito <amabito@local>
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
/**
|
|
* Unified abort error detection.
|
|
* Covers all known abort patterns in the Continue codebase:
|
|
* - String literal "cancel" (streaming cancellation)
|
|
* - Error with name "AbortError" (node-fetch, DOM)
|
|
* - Error with code "ABORT_ERR" (Node.js AbortSignal)
|
|
* - DOMException with name "AbortError" (browser/Node.js 18+)
|
|
* - Plain objects with name "AbortError" (serialized errors)
|
|
*/
|
|
export function isAbortError(error: unknown): boolean {
|
|
if (error === null || error === undefined) return false;
|
|
|
|
// String-based "cancel" (used in Continue streaming path)
|
|
if (error === "cancel") return true;
|
|
|
|
// Standard Error objects
|
|
if (error instanceof Error) {
|
|
if (error.name === "AbortError") return true;
|
|
if ("code" in error && (error as any).code === "ABORT_ERR") return true;
|
|
}
|
|
|
|
// DOMException (browser/Node.js 18+)
|
|
// In some runtimes DOMException does not extend Error, so check separately.
|
|
if (
|
|
typeof DOMException !== "undefined" &&
|
|
error instanceof DOMException &&
|
|
error.name === "AbortError"
|
|
) {
|
|
return true;
|
|
}
|
|
|
|
// Plain objects with name property (e.g. serialized errors across boundaries)
|
|
if (typeof error === "object" && "name" in error) {
|
|
const name = (error as any).name;
|
|
if (typeof name === "string" && name === "AbortError") return true;
|
|
}
|
|
|
|
return false;
|
|
}
|