Skip to content

WorkerError

Typed error model for worker APIs.

This module defines the WorkerError wrapper, the reason variants for spawn, send, receive, and unknown worker failures, a schema union for those reasons, and a guard for recognizing worker errors at runtime.

9 exports Added in v4.0.0 Source

Errors

WorkerError

Added in v4.0.0 Source

Error raised by worker APIs, wrapping a specific WorkerErrorReason and exposing its message and cause.

Signature

declare class WorkerError extends {
readonly _tag: "WorkerError";
readonly reason: WorkerSpawnError | WorkerSendError | WorkerReceiveError | WorkerUnknownError;
} & YieldableError<this> {
constructor(props: {
readonly reason: WorkerErrorReason;
});
readonly "~effect/workers/WorkerError": "~effect/workers/WorkerError";
message: string;
}

WorkerErrorReason type

Added in v4.0.0 Source

Union of the specific failure reasons that can be wrapped by a WorkerError.

Signature

type WorkerErrorReason =
| WorkerSpawnError
| WorkerSendError
| WorkerReceiveError
| WorkerUnknownError;

Worker error reason for failures while receiving or handling a message from a worker.

Signature

declare class WorkerReceiveError extends {
readonly _tag: "WorkerReceiveError";
readonly cause?: unknown;
readonly message: string;
} & YieldableError<this> {
constructor(...args: [props: {
readonly _tag?: "WorkerReceiveError";
readonly cause?: unknown;
readonly message: string;
}, options?: MakeOptions]);
}

Worker error reason for failures while sending a message to a worker.

Signature

declare class WorkerSendError extends {
readonly _tag: "WorkerSendError";
readonly cause?: unknown;
readonly message: string;
} & YieldableError<this> {
constructor(...args: [props: {
readonly _tag?: "WorkerSendError";
readonly cause?: unknown;
readonly message: string;
}, options?: MakeOptions]);
}

Worker error reason for failures while spawning or setting up a worker.

Signature

declare class WorkerSpawnError extends {
readonly _tag: "WorkerSpawnError";
readonly cause?: unknown;
readonly message: string;
} & YieldableError<this> {
constructor(...args: [props: {
readonly _tag?: "WorkerSpawnError";
readonly cause?: unknown;
readonly message: string;
}, options?: MakeOptions]);
}

Worker error reason for an unclassified worker failure.

Signature

declare class WorkerUnknownError extends {
readonly _tag: "WorkerUnknownError";
readonly cause?: unknown;
readonly message: string;
} & YieldableError<this> {
constructor(...args: [props: {
readonly _tag?: "WorkerUnknownError";
readonly cause?: unknown;
readonly message: string;
}, options?: MakeOptions]);
}

Guards

Returns true when a value is a WorkerError.

Signature

declare function isWorkerError(u: unknown): u is WorkerError;

Schemas

Schema for decoding and encoding all supported worker error reason variants.

Signature

declare const WorkerErrorReason: Union<
[
typeof WorkerSpawnError,
typeof WorkerSendError,
typeof WorkerReceiveError,
typeof WorkerUnknownError,
]
>;

Type IDs

TypeId type

Added in v4.0.0 Source

Type-level identifier used to brand WorkerError values.

Signature

type TypeId = typeof TypeId;