Classes

c
Failure.Failure<Code extends string = string, Data = unknown>(
code: Code,
message: string,
data: Data,
options?: FailureOptions
)

A structured, discriminable error.

Functions

f
Failure.attributes(failure: Any): TraceAttributes

Span/log attributes a failure declares for tracing: failure.code plus whatever its factory's trace mapper (see define) explicitly allowlisted from data. A failure whose factory declared no mapper yields the code alone — unmapped payload fields never leave the process, which is what makes redaction (passwords, tokens) the default rather than a discipline.

f
Failure.causes(error: unknown): unknown[]

Flattens an error's cause chain into an array, error first and the root cause last.

f
Failure.format(
error: unknown,
unnamed 1?: { stacks?: boolean; }
): string

Renders an error and its whole cause chain as indented, human-readable lines.

f
Failure.from(thrown: unknown): Any

Coerces any caught value into a Failure, leaving existing Failures untouched.

f
Failure.fromJSON(json: SerializedFailure): Any

Revives a SerializedFailure into a real Failure, reconstructing the cause chain.

f
Failure.hasCode<Codes extends readonly string[]>(
value: unknown,
...codes: Codes
): value is Failure<Codes[number], unknown>

Narrows a Failure to one of several codes — the multi-code sibling of Factory.is.

f
Failure.ignore(context: string): (error: unknown) => void

Builds a .catch() handler for a failure that genuinely has no consequence — but says so under QUNITX_DEBUG instead of vanishing. This is the raw handler; the ergonomic spelling at call sites is Task(promise).ignore(context), which wraps exactly this function.

f
Failure.is(value: unknown): value is Any

Whether value is a Failure — from this realm or any other.

f
Failure.is(value: unknown): value is Any

Whether value is a Failure — from this realm or any other.

f
Failure.isFactory(value: unknown): value is FailureFactory<string, never>

True for a factory made by define. A factory carries the code it produces and its own is guard; a plain error-mapper carries neither, so an API can accept both in one position and tell them apart exactly, without guessing from arity.

f
Failure.isFailure(value: unknown): value is Any

Whether value is a Failure — from this realm or any other.

f
Failure.isFailure(value: unknown): value is Any

Whether value is a Failure — from this realm or any other.

f
Failure.observed(failure: Any): void

Reports a declared failure to the observation seam — onObserved plus the OBSERVED_CHANNEL_NAME channel. Task's consuming methods call this at their classification points; call it yourself only for a synchronous Result flow that never crossed a Task, so a tracing adapter sees those failures too.

f
Failure.onIgnored(observer: IgnoredObserver | null): void

Installs a process-wide observer for every ignored failure — the interception seam for "list everything the program decided not to handle". Costs one null check on the failure path only (nothing on success, nothing per Task), and retains nothing itself: whether the suppressed failures accumulate, sample, or stream somewhere is the observer's decision. Pass null to detach.

f
Failure.onObserved(observer: ObservedObserver | null): void

Installs a process-wide observer for every handled declared failure — the portable (browser-friendly) counterpart of subscribing to OBSERVED_CHANNEL_NAME. Single slot, one null check on the failure path, nothing retained; pass null to detach.

f
Failure.rootCause(error: unknown): unknown

The deepest cause in the chain — the original failure, whatever wrapped it since.

f
Failure.setDebug(enabled: boolean): void

Toggles ignored-failure reporting at runtime, overriding the QUNITX_DEBUG default.

f
Failure.toJSON(error: unknown): SerializedFailure

Converts a Failure (or any error) into plain JSON.

Interfaces

I
Channel

The producer half of StreamClass.channel: emit into it, consume stream out of it.

  • abort(reason: unknown): void

    Rejects the consuming Task with reason — the two-tier rule's bug tier. Idempotent.

  • buffered: number

    Elements buffered for a consumer that has not taken them yet.

  • close(): void

    Ends the stream once the buffer drains. Idempotent.

  • closed: boolean

    Whether the channel has been closed, aborted, or abandoned by its consumer.

  • dropped: number

    How many elements the buffer has lost to overflow. 0 unless a consumer fell behind.

  • emit(value: T): boolean

    Offers a value. Returns false when there is no room left — Node's write() convention: advisory for a producer that can slow down, ignorable for one that cannot.

  • fail(error: E): boolean

    Offers a declared failure as an element — the railway, not a rejection.

  • ready(): Promise<void>

    Resolves once there is room to emit again — Web Streams' writer.ready, and the promise form of Node's 'drain'.

  • stream: Stream<T, E>

    The consuming half. One consumer only; a second pass throws.

I
ChannelOptions

How a Channel behaves when its consumer cannot keep up.

  • capacity: number

    How many elements to buffer for a consumer that has not taken them yet. Default 10_000.

  • onDemand: () => void

    Called once, when a consumer first attaches. A producer that can defer starting should start here: it is the difference between a buffer that stays near empty and one that races ahead of a consumer that has not arrived.

  • onDiscard: (
    dropped: T | E,
    buffered: number
    ) => void

    Called with each element the buffer actually lost, and the depth after the loss. The only place overflow is observable — make it fatal from here by calling fail or abort.

  • overflow: Overflow

    What to do once capacity is reached: drop from either end, or 'fail' — end the stream with a ChannelOverflowFailure element instead of losing anything quietly. Default 'dropOldest'.

I
Failure.DefineOptions

Per-kind options accepted by define().

  • trace: (data: Data) => TraceAttributes

    Allowlist mapper from the typed payload to span/log attributes, consumed by attributes. Deliberately not a redaction filter: only what the mapper returns is ever exposed, so sensitive fields are private by omission, not by scrubbing.

I
Failure.FailureFactory

A callable failure constructor produced by define(), carrying its own type guard.

I
Failure.FailureOptions

Options accepted by the Failure constructor and by every generated factory.

  • cause: unknown

    The error this failure was derived from. Preserved verbatim and walked by causes().

  • stackAnchor: (...args: never[]) => unknown

    The function to truncate the stack at, so the top frame is the code that reported the failure rather than the plumbing that built it. Defaults to the constructor.

  • stackless: boolean

    Skips stack capture. Only worth setting for failures produced in a hot loop and consumed immediately — the capture, not the allocation, is what a Failure costs. See the performance section of the docs before reaching for it.

I
Failure.SerializedFailure

The wire form of a Failure — what toJSON emits and fromJSON accepts.

  • cause:
    SerializedFailure
    | { name: string; message: string; stack?: string; }

    The serialized cause chain: a nested Failure, or a plain error's identifying fields.

  • code: string

    The discriminant. Survives the wire, unlike a prototype.

  • data: unknown

    The structured payload, JSON round-tripped by toJSON so it cannot fail later.

  • failure: true

    Wire marker. Symbol.for keys survive neither JSON.stringify nor structuredClone, so the serialized form carries an explicit field in the brand's place.

  • message: string

    The human-readable sentence, already interpolated from data.

  • stack: string

    The producing process's stack. Frameless — the header line alone — when the failure was built { stackless: true }; the field itself is absent only if stack was never set.

Namespaces

N
Failure

Structured, discriminable failures — the E elements of a Stream.

Type Aliases

T
ChannelOverflowFailure = Of<ChannelOverflow>

The failure element a 'fail' channel ends with.

T
Failure.Any = Failure<string, unknown>

Any Failure at all — the type to reach for when a signature accepts failures it does not enumerate, e.g. Result<T, Failure.Any> at a boundary that only logs.

T
Failure.IgnoredObserver = (
context: string,
error: unknown
) => void

The callback shape onIgnored installs: every ignored failure arrives with the label its call site declared.

T
Failure.ObservedObserver = (failure: Any) => void

The callback shape onObserved installs: every declared failure a consumer classified arrives right as it is handed to application code.

T
Failure.Of<F> = F extends FailureFactory<infer Code, infer Data> ? Failure<Code, Data> : never

The Failure type a factory produces: Failure.Of<typeof FileMissing>.

T
Failure.TraceAttributes = Record<string, string | number | boolean>

The attribute primitives tracing systems accept (OpenTelemetry's span-attribute values) — what a trace mapper returns and attributes yields.

T
Overflow = "dropOldest" | "dropNewest" | "fail"

What a full channel does — the two GenStage :buffer_keep choices, named for the element that goes rather than the one that stays, plus the option of refusing to lose anything silently.

T
Source<T> = AsyncIterable<T> | Iterable<T>

Anything a Stream can be built from or flattened into: sync or async iterables (a web ReadableStream is async-iterable on every modern runtime).

Variables

v
ChannelOverflow: FailureFactory<"ChannelOverflow", { capacity: number; }>

A channel with overflow: 'fail' filled up: the consumer fell far enough behind that the buffer could not hold the difference, and dropping was not on the table.

v
Failure.IGNORED_CHANNEL_NAME: "qunitx.failure.ignored"

Name of the diagnostics_channel that ignore publishes to on Node and Deno — subscribe with the platform API, no qunitx registry involved. Messages are { context: string, error: unknown }. Browsers have no channel; use onIgnored.

v
Failure.OBSERVED_CHANNEL_NAME: "qunitx.failure.observed"

Name of the diagnostics_channel that observed publishes to on Node and Deno. Messages are { error: Failure.Any }. This is what a tracing adapter subscribes to — e.g. OpenTelemetry, in its entirety:

v
Failure.Unknown: FailureFactory<"Unknown", { thrown: unknown; }>

The failure from() produces for a throwable that is not already a Failure.

v
T
Stream

The exported value: builders (Stream.from, Stream.unfold, Stream.lines) are the only entry points — there is no public constructor and no call form.

v
T
Stream

The exported value: builders (Stream.from, Stream.unfold, Stream.lines) are the only entry points — there is no public constructor and no call form.

v
T
Task: TaskConstructor

Call-or-construct, like Boolean/Date: Task(recipe) and new Task(recipe) build the same lazy Task. ES classes reject the call form, so the export is a Proxy whose apply forwards to construction — statics, instanceof, and the prototype all pass through.

v
T
Task: TaskConstructor

Call-or-construct, like Boolean/Date: Task(recipe) and new Task(recipe) build the same lazy Task. ES classes reject the call form, so the export is a Proxy whose apply forwards to construction — statics, instanceof, and the prototype all pass through.