Hyperlinkv0.8.0-beta.28

Cause

Cause.prettyErrorsconsteffect/Cause.ts:1111
<E>(
  self: Cause<E>,
  options?: { readonly includeCauseInStack?: boolean | undefined }
): Array<Error>

Converts a Cause into an Array<Error> suitable for logging or rethrowing.

When to use

Use to convert every renderable failure in a cause into individual Error values before logging or rethrowing.

Details

Each Fail and Die reason is converted into a standard Error:

  • Objects / Error instancesmessage, name, stack, and cause are preserved. Extra enumerable properties are copied. Stack traces are cleaned up and enriched with span annotations when available.
  • Strings — used directly as the Error message.
  • Other primitives (null, undefined, numbers, …) — wrapped in an Error with message "Unknown error: <value>".

Interrupt reasons are collected separately. If the cause contains only interrupts (no Fail or Die), a single InterruptError is returned whose cause lists the interrupting fiber IDs.

An empty cause returns an empty array.

Example (Converting a cause to errors)

import { Cause } from "effect"

const cause = Cause.fail(new Error("boom"))
const errors = Cause.prettyErrors(cause)
console.log(errors[0].message) // "boom"
renderingprettysquash
Source effect/Cause.ts:11113 lines
export const prettyErrors: <E>(self: Cause<E>, options?: {
  readonly includeCauseInStack?: boolean | undefined
}) => Array<Error> = effect.causePrettyErrors