Hyperlinkv0.8.0-beta.28

Cause

Cause.squashconsteffect/Cause.ts:756
<E>(self: Cause<E>): unknown

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"
Source effect/Cause.ts:7561 lines
export const squash: <E>(self: Cause<E>) => unknown = effect.causeSquash
Referenced by 7 symbols