interface SerializedFailure

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

Properties

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.

It is load-bearing rather than decorative: without it the structural check in isFailure() would have to accept "has a string code and a string message", and every Node system error satisfies that — an ENOENT would report itself as a Failure and error.data would silently read undefined from there on.

code: string

The discriminant. Survives the wire, unlike a prototype.

message: string

The human-readable sentence, already interpolated from data.

data: unknown

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

optional
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.

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

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

Usage

import { type SerializedFailure } from "lib/result/failure.ts";