Skip to main content

Error hierarchy

All hurried errors extend HurriedError, so you can instanceof HurriedError to detect anything from the library.

HurriedError

Base class. instanceof HurriedError matches every other library error.

TaskError

A handler threw or rejected. The original error is on .cause:

try {
await thread.run('process', data);
} catch (e) {
if (e instanceof TaskError) {
console.error('handler failed:', e.cause);
}
}

TaskTimeoutError

The call exceeded its timeout. .timeoutMs carries the configured deadline.

try {
await thread.run(arg, { timeout: 500 });
} catch (e) {
if (e instanceof TaskTimeoutError) retryWithLongerTimeout();
}

TaskAbortedError

An AbortSignal fired during the call.

const controller = new AbortController();
setTimeout(() => controller.abort(), 100);

try {
await thread.run(arg, { signal: controller.signal });
} catch (e) {
if (e instanceof TaskAbortedError) { /* swallow */ }
}

TerminatedError

The worker was deliberately torn down mid-flight via terminate().

const promise = thread.run(arg);
await thread.terminate(); // promise rejects with TerminatedError

WorkerExitedError

The worker exited on its ownprocess.exit() in task code, an OOM, or a fatal native error — rather than being terminated. Kept distinct from TerminatedError so the *Settled helpers can treat a crashed worker as a recoverable per-item failure instead of a deliberate stop. Exposes the exit code when the runtime reports one.

try {
await thread.run(arg);
} catch (e) {
if (e instanceof WorkerExitedError) respawn();
}