Sample
es-toolkit 1.50.0: Handle es-toolkit AbortError name defaulting to 'Error' and code defaulting to 0
Verified sample for npm es-toolkit 1.50.0: Handle es-toolkit AbortError name defaulting to 'Error' and code defaulting to 0. The contract ran on node 22 …
sha256:248e285b14a91c88ba52065b200f8a090be882be704fd8d3fd458230a10b18d3
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 2
- Signing keys that built it
- 2
Declared environment
node linux x64 node node npm
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-18 |
| node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-18 |
Case
HOW- Goal
- Handle es-toolkit AbortError name defaulting to 'Error' and code defaulting to 0
- Packages
- Symbols
-
- AbortError
- Environment
- node
- Created
- 2026-08-18T00:45:52Z
Contract
- AbortError instances have name set to 'Error' and code set to 0 rather than 'AbortError' and 20 because its constructor extends DOMException and invokes super(message) without the name argument
- AbortError constructor is exported identically from the package root and es-toolkit/error subpath
- delay rejects on aborted signal with an AbortError whose name is 'Error' and code is 0, discarding any custom signal reason
- catching AbortError requires instanceof or constructor.name checks rather than error.name equality
- isError returns true for AbortError while compat isError returns false due to the [object DOMException] tag
Files
- NOTES.md
- csx.json
- package-lock.json
- package.json
- test/contract.mjs
Source
# es-toolkit AbortError Behavior and Inspection
`search_known_solution` returned a compatible match (`sha256:9811ac8f7ba7d61b88f548947571505c7109ac7eecfba9d6fabbadd5b85defff`), which covered generic name defaulting across both `TimeoutError` and `AbortError`. This sample investigates and proves the specific runtime behaviors, export structure, and cancellation mechanics of `AbortError` in `es-toolkit@1.50.0`.
## Pinned Release
- Package: `es-toolkit`
- Version: `1.50.0` (pinned in `package.json` and `package-lock.json`)
## Observed Behavior
### 1. `AbortError` Constructor and DOMException Inheritance
In `es-toolkit@1.50.0`, `AbortError` is defined as:
```javascript
class AbortError extends DOMException {
constructor(message = "The operation was aborted") {
super(message);
}
}
```
Because `DOMException`'s constructor accepts `(message, name)` and defaults `name` to `'Error'` when the second parameter is omitted:
- `error.name` evaluates to `'Error'` instead of `'AbortError'`.
- `error.code` evaluates to `0` instead of `DOMException.ABORT_ERR` (`20`).
- `error.message` defaults to `'The operation was aborted'`. When provided a custom message (`new AbortError('Cancelled')`), `.message` is updated, but `.name` remains `'Error'`.
- `error.constructor.name` evaluates to `'AbortError'`.
- `error instanceof AbortError`, `error instanceof DOMException`, and `error instanceof Error` all evaluate to `true`.
### 2. Export Locations
`AbortError` is exported identically from:
- Root entry point: `import { AbortError } from 'es-toolkit'`
- Error subpath: `import { AbortError } from 'es-toolkit/error'`
Both export paths refer to the exact same constructor function.
### 3. Cancellation in Asynchronous Utilities (`delay`)
When an `AbortSignal` is provided to `delay(ms, { signal })`:
- When triggered, `delay` creates and rejects with a new `new AbortError()` whose `.name` is `'Error'` and `.code` is `0`.
- Even if `controller.abort(customReason)` is called with a specific reason or error object, `delay` discards `signal.reason` and always rejects with `new AbortError()`.
- If the signal is already aborted prior to calling `delay`, the promise rejects immediately on the current event loop turn without initiating a timer.
### 4. Predicate Behavior Across Subpaths
- `isError` from `es-toolkit/predicate` evaluates `value instanceof Error`, returning `true` for `AbortError` instances.
- `isError` from `es-toolkit/compat` checks `Object.prototype.toString.call(value) === '[object Error]'`. Because DOMException objects return `[object DOMException]`, `compat.isError` returns `false` for `AbortError` instances.
## Failure Mode
Code that inspects `error.name === 'AbortError'` fails silently at runtime with a green build, as `error.name` is `'Error'`. Catch blocks relying on `.name` discrimination will misclassify abort events as unexpected runtime errors. Robust discrimination must check `error instanceof AbortError` or `error.constructor.name === 'AbortError'`.
{"case":{"believed":"Instantiating or catching AbortError yields an error object whose name property is 'AbortError' and code is 20 (DOMException.ABORT_ERR).","caseId":"case:sha256:b6e569a8fd1eca99ac6669a6f439a7275073d3b49cead5ea703a2aaa1840c04b","contract":["AbortError instances have name set to 'Error' and code set to 0 rather than 'AbortError' and 20 because its constructor extends DOMException and invokes super(message) without the name argument","AbortError constructor is exported identically from the package root and es-toolkit/error subpath","delay rejects on aborted signal with an AbortError whose name is 'Error' and code is 0, discarding any custom signal reason","catching AbortError requires instanceof or constructor.name checks rather than error.name equality","isError returns true for AbortError while compat isError returns false due to the [object DOMException] tag"],"goal":"Handle es-toolkit AbortError name defaulting to 'Error' and code defaulting to 0","kind":"HOW","packages":["pkg:npm/es-toolkit@1.50.0"],"schemaVersion":1,"symbols":["AbortError"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"node","os":"linux","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/es-toolkit@1.50.0"],"schemaVersion":1,"symbols":["AbortError"],"verifierAdapter":"node-typescript@1"}
{
"name": "npm-es-toolkit-wanted-1-50-0-aborterror-be6e9b6a22b0a261af545274",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "npm-es-toolkit-wanted-1-50-0-aborterror-be6e9b6a22b0a261af545274",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"es-toolkit": "1.50.0"
}
},
"node_modules/es-toolkit": {
"version": "1.50.0",
"resolved": "https://registry.npmjs.org/es-toolkit/-/es-toolkit-1.50.0.tgz",
"integrity": "sha512-OyZKhUVvEep9ITEiwHn8GKnMRQIVqoSIX7WnRbkWgJkllCujilqP2rD0u979tkl8wqyc8ICwlc1UBVv/Sl1G6w==",
"license": "MIT",
"workspaces": [
"docs",
"benchmarks",
"tests/types"
]
}
}
}
{
"name": "npm-es-toolkit-wanted-1-50-0-aborterror-be6e9b6a22b0a261af545274",
"version": "1.0.0",
"private": true,
"type": "module",
"license": "MIT-0",
"dependencies": {
"es-toolkit": "1.50.0"
}
}
import { strict as assert } from 'node:assert';
import { AbortError } from 'es-toolkit';
import { AbortError as SubpathAbortError } from 'es-toolkit/error';
import { delay } from 'es-toolkit/promise';
import { isError } from 'es-toolkit/predicate';
import { isError as compatIsError } from 'es-toolkit/compat';
// 1. Export Parity: AbortError is exported at root and from 'es-toolkit/error'
assert.strictEqual(
AbortError,
SubpathAbortError,
'AbortError root export and subpath export point to the exact same constructor'
);
// 2. Direct Instantiation & Name Property Behavior:
// In es-toolkit, AbortError extends DOMException with constructor(message = "The operation was aborted") { super(message); }.
// Because the second argument (name) is omitted in super(), DOMException defaults .name to 'Error' rather than 'AbortError'.
const err = new AbortError();
assert.strictEqual(
err.name,
'Error',
"AbortError.name is 'Error' rather than 'AbortError' because DOMException defaults name to 'Error' when super() omits the name parameter"
);
assert.notStrictEqual(
err.name,
'AbortError',
"AbortError.name is NOT 'AbortError'"
);
assert.strictEqual(err.message, 'The operation was aborted');
assert.strictEqual(err.code, 0, 'AbortError.code is 0 rather than DOMException.ABORT_ERR (20)');
assert.strictEqual(err.constructor.name, 'AbortError');
// Inheritance chain
assert.ok(err instanceof AbortError, 'instanceof AbortError is true');
assert.ok(err instanceof DOMException, 'instanceof DOMException is true');
assert.ok(err instanceof Error, 'instanceof Error is true');
// Custom message instantiation
const customErr = new AbortError('Task was cancelled');
assert.strictEqual(customErr.message, 'Task was cancelled');
assert.strictEqual(customErr.name, 'Error', 'Custom message still leaves name as Error');
assert.strictEqual(customErr.code, 0);
// 3. Contrast with standard DOMException AbortError:
// Standard DOMException('message', 'AbortError') sets .name to 'AbortError' and .code to 20 (ABORT_ERR).
const nativeAbort = new DOMException('Operation aborted', 'AbortError');
assert.strictEqual(nativeAbort.name, 'AbortError');
assert.strictEqual(nativeAbort.code, 20);
assert.strictEqual(DOMException.ABORT_ERR, 20);
assert.notStrictEqual(err.name, nativeAbort.name);
assert.notStrictEqual(err.code, nativeAbort.code);
// 4. Asynchronous cancellation behavior with delay():
// delay rejects on an aborted signal with es-toolkit's AbortError (name: 'Error', code: 0)
const controller = new AbortController();
const delayPromise = delay(100, { signal: controller.signal });
controller.abort(new Error('Custom abort reason'));
let caughtError;
try {
await delayPromise;
} catch (e) {
caughtError = e;
}
assert.ok(caughtError instanceof AbortError, 'delay rejection is an instance of AbortError');
assert.strictEqual(caughtError.name, 'Error', "delay rejection name is 'Error'");
assert.strictEqual(caughtError.code, 0);
assert.strictEqual(
caughtError.message,
'The operation was aborted',
'delay creates a new AbortError with default message, ignoring signal.reason'
);
// Pre-aborted signal rejects immediately with AbortError
const preAbortedController = new AbortController();
preAbortedController.abort();
let preAbortedError;
try {
await delay(1000, { signal: preAbortedController.signal });
} catch (e) {
preAbortedError = e;
}
assert.ok(preAbortedError instanceof AbortError);
assert.strictEqual(preAbortedError.name, 'Error');
// 5. Error discrimination: checking error.name fails while instanceof succeeds
function isAbortFailure(e) {
return {
byName: e?.name === 'AbortError',
byInstance: e instanceof AbortError,
byConstructorName: e?.constructor?.name === 'AbortError',
};
}
const checkResult = isAbortFailure(caughtError);
assert.strictEqual(checkResult.byName, false, 'Checking error.name === AbortError fails silently');
assert.strictEqual(checkResult.byInstance, true, 'instanceof AbortError succeeds');
assert.strictEqual(checkResult.byConstructorName, true, 'constructor.name === AbortError succeeds');
// 6. Predicate function behavior across modules:
// isError from 'es-toolkit/predicate' uses (value instanceof Error) -> returns true
// isError from 'es-toolkit/compat' uses Object.prototype.toString.call(value) === '[object Error]' -> returns false for DOMException
assert.strictEqual(
isError(err),
true,
'es-toolkit isError returns true for AbortError (instanceof Error)'
);
assert.strictEqual(
compatIsError(err),
false,
'es-toolkit/compat isError returns false for AbortError because DOMException tag is [object DOMException]'
);
assert.strictEqual(
Object.prototype.toString.call(err),
'[object DOMException]',
'DOMException instances have [object DOMException] tag'
);
console.log('CONTRACT PASS: AbortError behavior verified for es-toolkit 1.50.0');