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

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

Node's own util.inspect renders cause chains well, but only for real Error objects and only when something calls it — this works on revived wire failures too, and is what you want in a TAP comment or a CLI's stderr block where a full stack would be noise.

import * as Failure from './failure.ts';

const GitScanFailed = Failure.define('GitScanFailed', (d: { ref: string }) => `bad ref: ${d.ref}`);
const failure = GitScanFailed({ ref: 'HEAD' }, { cause: new Error('spawn git ENOENT') });

Failure.format(failure);
// GitScanFailed: bad ref: HEAD
//   caused by: Error: spawn git ENOENT
Failure.format(failure, { stacks: true }); // same, with indented frames under each link

Parameters

error: unknown
optional
unnamed 1: { stacks?: boolean; }

Return Type

string

Usage

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