effect-io-ai

Package: effect
Module: Cause

Cause.squash

Collapses a Cause into a single unknown value, picking the “most important” failure in this order:

When to use

Use to collapse a structured cause to the single value that synchronous and promise runners would throw.

Details

  1. First Fail error (the E value)
  2. First Die defect
  3. A generic Error("All fibers interrupted without error") for interrupt-only causes
  4. A generic Error("Empty cause") for empty

This is the function used by Effect.runPromise and Effect.runSync to decide what to throw.

Gotchas

This function is lossy. Use prettyErrors or iterate cause.reasons when you need all failures.

Example (Squashing a cause)

import { Cause } from "effect"

console.log(Cause.squash(Cause.fail("error")))    // "error"
console.log(Cause.squash(Cause.die("defect")))    // "defect"

See

Signature

declare const squash: <E>(self: Cause<E>) => unknown

Source

Since v2.0.0