<E>(self: Cause<E>): Result.Result<Fail<E>, Cause<never>>Returns a Result whose success value is the first Fail reason in
the cause, including its annotations. If the cause has no Fail reason, the
failure value is the original cause narrowed to Cause<never>, because it
contains no typed error reasons.
When to use
Use when you need the full Fail reason from a Cause, including
annotations.
Example (Extracting the first Fail reason)
import { Cause, Result } from "effect"
const result = Cause.findFail(Cause.fail("error"))
if (!Result.isFailure(result)) {
console.log(result.success.error) // "error"
}export const const findFail: <E>(
self: Cause<E>
) => Result.Result<Fail<E>, Cause<never>>
Returns a Result whose success value is the first Fail reason in
the cause, including its annotations. If the cause has no Fail reason, the
failure value is the original cause narrowed to Cause<never>, because it
contains no typed error reasons.
When to use
Use when you need the full Fail reason from a Cause, including
annotations.
Example (Extracting the first Fail reason)
import { Cause, Result } from "effect"
const result = Cause.findFail(Cause.fail("error"))
if (!Result.isFailure(result)) {
console.log(result.success.error) // "error"
}
findFail: <function (type parameter) E in <E>(self: Cause<E>): Result.Result<Fail<E>, Cause<never>>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>): Result.Result<Fail<E>, Cause<never>>E>) => import ResultResult.type Result<A, E = never> = Result.Success<A, E> | Result.Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<interface Fail<out E>A typed, expected error produced by Effect.fail.
When to use
Use when inspecting Cause reasons that represent expected failures from the
typed error channel.
Details
The error property carries the typed value E. Use
isFailReason
to narrow a Reason to this type.
Example (Accessing the error)
import { Cause } from "effect"
const cause = Cause.fail("Something went wrong")
const reason = cause.reasons[0]
if (Cause.isFailReason(reason)) {
console.log(reason.error) // "Something went wrong"
}
Fail<function (type parameter) E in <E>(self: Cause<E>): Result.Result<Fail<E>, Cause<never>>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<never>> = import effecteffect.const findFail: <E>(
self: Cause.Cause<E>
) => Result.Result<
Cause.Fail<E>,
Cause.Cause<never>
>
findFail