function causeMessage
Since 0.6.0
causeMessage(cause: unknown): string

Extracts a caller-facing message from an unknown thrown value.

The one-line counterpart of serializeError: that turns a thrown value into a structured record for a log sink, this turns it into the sentence that goes inside another error's message.

It is published because two packages must produce the SAME sentence and §2.2 forbids the import that would let one read the other's copy. resolveRegistryEntry uses it for a factory that threw, and @setu-ts/scheduler-plugin for a declared job that could not be scheduled — the two arms of one jobs option, which have to be indistinguishable to an operator reading the failure. A local copy in each was byte-identical and free to drift.

Examples

Example 1

throw new Error(`Failed to start: ${causeMessage(cause)}`, { cause });

Parameters

cause: unknown

The value that was thrown

Return Type

string

Its message, or a stable fallback when it is not an Error

Usage

import { causeMessage } from "common/src/index.ts";