function causes
causes(error: unknown): unknown[]

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

Cycle-safe and depth-bounded: a repeated reference terminates the walk instead of looping.

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

const FileMissing = Failure.define('FileMissing', (d: { path: string }) => `no such file: ${d.path}`);

const root = new Error('EACCES');
const wrapped = FileMissing({ path: 'a.ts' }, { cause: root });
Failure.causes(wrapped); // [wrapped, root]

Parameters

error: unknown

Return Type

unknown[]

Usage

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