<E>(reasons: ReadonlyArray<Reason<E>>): Cause<E>Creates a Cause from an array of Reason values.
When to use
Use when you already have individual reasons (e.g. from filtering or
transforming another cause's reasons array) and need to wrap them back
into a Cause.
Details
- Returns a new
Cause. - An empty array produces a cause equivalent to
empty.
Gotchas
The reasons array is stored as provided. Treat the array as immutable
after passing it to this function.
Example (Building a cause from reasons)
import { Cause } from "effect"
const reasons = [
Cause.makeFailReason("err1"),
Cause.makeFailReason("err2")
]
const cause = Cause.fromReasons(reasons)
console.log(cause.reasons.length) // 2export const const fromReasons: <E>(
reasons: ReadonlyArray<Reason<E>>
) => Cause<E>
Creates a Cause from an array of Reason values.
When to use
Use when you already have individual reasons (e.g. from filtering or
transforming another cause's reasons array) and need to wrap them back
into a Cause.
Details
- Returns a new
Cause.
- An empty array produces a cause equivalent to
empty.
Gotchas
The reasons array is stored as provided. Treat the array as immutable
after passing it to this function.
Example (Building a cause from reasons)
import { Cause } from "effect"
const reasons = [
Cause.makeFailReason("err1"),
Cause.makeFailReason("err2")
]
const cause = Cause.fromReasons(reasons)
console.log(cause.reasons.length) // 2
fromReasons: <function (type parameter) E in <E>(reasons: ReadonlyArray<Reason<E>>): Cause<E>E>(
reasons: ReadonlyArray<Reason<E>>reasons: interface ReadonlyArray<T>ReadonlyArray<type Reason<E> = Fail<E> | Die | InterruptA single entry inside a Cause's reasons array.
Details
Narrow to a concrete type with
isFailReason
,
isDieReason
,
or
isInterruptReason
.
Fail<E> — typed error, access via .error
Die — untyped defect, access via .defect
Interrupt — fiber interruption, access via .fiberId
Every reason carries an annotations map and an annotate method for
attaching tracing metadata.
Example (Narrowing a reason)
import { Cause } from "effect"
const reason = Cause.fail("error").reasons[0]
if (Cause.isFailReason(reason)) {
console.log(reason.error) // "error"
}
Companion namespace for the Reason type.
Reason<function (type parameter) E in <E>(reasons: ReadonlyArray<Reason<E>>): Cause<E>E>>
) => 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>(reasons: ReadonlyArray<Reason<E>>): Cause<E>E> = import corecore.const causeFromReasons: <E>(
reasons: ReadonlyArray<Cause.Reason<E>>
) => Cause.Cause<E>
causeFromReasons