<E>(self: Cause<E>): unknownCollapses 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
- First
Failerror (theEvalue) - First
Diedefect - A generic
Error("All fibers interrupted without error")for interrupt-only causes - A generic
Error("Empty cause")forempty
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"export const const squash: <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
- First
Fail error (the E value)
- First
Die defect
- A generic
Error("All fibers interrupted without error") for interrupt-only causes
- 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"
squash: <function (type parameter) E in <E>(self: Cause<E>): unknownE>(self: Cause<E>(parameter) self: {
reasons: ReadonlyArray<Reason<E>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self: interface Cause<out E>A structured representation of how an Effect failed.
When to use
Use to preserve the full structured failure information for an effect instead
of collapsing it to a single error value.
Details
Access the individual failure entries through the reasons array, then
narrow each entry with
isFailReason
,
isDieReason
, or
- Use
hasFails
/
hasDies
/
hasInterrupts
to test
for the presence of specific reason kinds without iterating.
- Use
findError
/
findDefect
to extract the first value
of a given kind.
- Use
combine
to merge two causes.
Cause implements Equal — two causes with the same reasons (by value)
compare as equal.
Example (Creating and inspecting a cause)
import { Cause } from "effect"
const cause = Cause.fail("Something went wrong")
console.log(cause.reasons.length) // 1
console.log(Cause.isFailReason(cause.reasons[0])) // true
Companion namespace for the Cause interface.
Cause<function (type parameter) E in <E>(self: Cause<E>): unknownE>) => unknown = import effecteffect.const causeSquash: <E>(
self: Cause.Cause<E>
) => unknown
causeSquash