variable Failure

The failure taxonomy, as this API's public surface.

A hand-picked subset rather than the internal module re-exported whole: these three are what a consumer needs in order to handle a failure, and freezing only them leaves the rest — define, the tracing hooks, the ignore channel — free to change without breaking anyone.

import { Failure } from './index.ts';

Failure.is(new Error('plain')); // false — only declared failures answer to this

Properties

is: (value: unknown) => value is AnyFailure

Narrows an unknown value to a declared failure. The guard to reach for after .result().

format: (
error: unknown,
options?: { stacks?: boolean; }
) => string

Renders a failure as the one-line message the CLI would print.

hasCode: <Codes extends readonly string[]>(
value: unknown,
...codes: Codes
) => value is AnyFailure & { code: Codes[number]; }

Narrows to a specific set of codes, for handling some failures and rethrowing the rest.

Usage

import { Failure } from "lib/api/index.ts";