<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 instances —
message,name,stack, andcauseare preserved. Extra enumerable properties are copied. Stack traces are cleaned up and enriched with span annotations when available. - Strings — used directly as the
Errormessage. - Other primitives (
null,undefined, numbers, …) — wrapped in anErrorwith 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"export const const prettyErrors: <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 instances —
message, 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"
prettyErrors: <function (type parameter) E in <E>(self: Cause<E>, options?: {
readonly includeCauseInStack?: boolean | undefined;
}): Array<Error>
E>(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>, options?: {
readonly includeCauseInStack?: boolean | undefined;
}): Array<Error>
E>, options: | {
readonly includeCauseInStack?:
| boolean
| undefined
}
| undefined
options?: {
readonly includeCauseInStack?: boolean | undefinedincludeCauseInStack?: boolean | undefined
}) => interface Array<T>Array<Error> = import effecteffect.const causePrettyErrors: <E>(
self: Cause.Cause<E>,
options?: {
readonly includeCauseInStack?:
| boolean
| undefined
}
) => Array<Error>
causePrettyErrors