Reason<E>A 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.errorDie— untyped defect, access via.defectInterrupt— 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"
}export type 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 type Reason<E>E> = 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 type Reason<E>E> | Die | Interrupt
/**
* Narrows a `Reason` to `Fail`.
*
* **When to use**
*
* Use as a predicate for `Array.filter` to pick out typed `Fail` reasons when
* iterating over `cause.reasons`.
*
* **Example** (Filtering fail reasons)
*
* ```ts
* import { Cause } from "effect"
*
* const cause = Cause.fail("error")
* const fails = cause.reasons.filter(Cause.isFailReason)
* console.log(fails[0].error) // "error"
* ```
*
* @see {@link isDieReason} — narrow to `Die`
* @see {@link isInterruptReason} — narrow to `Interrupt`
*
* @category guards
* @since 4.0.0
*/
export const const isFailReason: <E>(
self: Reason<E>
) => self is Fail<E>
Narrows a Reason to Fail.
When to use
Use as a predicate for Array.filter to pick out typed Fail reasons when
iterating over cause.reasons.
Example (Filtering fail reasons)
import { Cause } from "effect"
const cause = Cause.fail("error")
const fails = cause.reasons.filter(Cause.isFailReason)
console.log(fails[0].error) // "error"
isFailReason: <function (type parameter) E in <E>(self: Reason<E>): self is Fail<E>E>(self: Reason<E>self: 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>(self: Reason<E>): self is Fail<E>E>) => self: Reason<E>self is 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: Reason<E>): self is Fail<E>E> = import corecore.const isFailReason: <E>(
self: Cause.Reason<E>
) => self is Cause.Fail<E>
isFailReason
/**
* Narrows a `Reason` to `Die`.
*
* **When to use**
*
* Use as a predicate for `Array.filter` to pick out `Die` (defect) reasons when
* iterating over `cause.reasons`.
*
* **Example** (Filtering die reasons)
*
* ```ts
* import { Cause } from "effect"
*
* const cause = Cause.die("defect")
* const dies = cause.reasons.filter(Cause.isDieReason)
* console.log(dies[0].defect) // "defect"
* ```
*
* @see {@link isFailReason} — narrow to `Fail`
* @see {@link isInterruptReason} — narrow to `Interrupt`
*
* @category guards
* @since 4.0.0
*/
export const const isDieReason: <E>(
self: Reason<E>
) => self is Die
Narrows a Reason to Die.
When to use
Use as a predicate for Array.filter to pick out Die (defect) reasons when
iterating over cause.reasons.
Example (Filtering die reasons)
import { Cause } from "effect"
const cause = Cause.die("defect")
const dies = cause.reasons.filter(Cause.isDieReason)
console.log(dies[0].defect) // "defect"
isDieReason: <function (type parameter) E in <E>(self: Reason<E>): self is DieE>(self: Reason<E>self: 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>(self: Reason<E>): self is DieE>) => self: Reason<E>self is Die = import corecore.const isDieReason: <E>(
self: Cause.Reason<E>
) => self is Cause.Die
isDieReason
/**
* Narrows a `Reason` to `Interrupt`.
*
* **When to use**
*
* Use as a predicate for `Array.filter` to pick out `Interrupt` reasons when
* iterating over `cause.reasons`.
*
* **Example** (Filtering interrupt reasons)
*
* ```ts
* import { Cause } from "effect"
*
* const cause = Cause.interrupt(123)
* const interrupts = cause.reasons.filter(Cause.isInterruptReason)
* console.log(interrupts[0].fiberId) // 123
* ```
*
* @see {@link isFailReason} — narrow to `Fail`
* @see {@link isDieReason} — narrow to `Die`
*
* @category guards
* @since 4.0.0
*/
export const const isInterruptReason: <E>(
self: Reason<E>
) => self is Interrupt
Narrows a Reason to Interrupt.
When to use
Use as a predicate for Array.filter to pick out Interrupt reasons when
iterating over cause.reasons.
Example (Filtering interrupt reasons)
import { Cause } from "effect"
const cause = Cause.interrupt(123)
const interrupts = cause.reasons.filter(Cause.isInterruptReason)
console.log(interrupts[0].fiberId) // 123
isInterruptReason: <function (type parameter) E in <E>(self: Reason<E>): self is InterruptE>(self: Reason<E>self: 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>(self: Reason<E>): self is InterruptE>) => self: Reason<E>self is Interrupt = import corecore.const isInterruptReason: <E>(
self: Cause.Reason<E>
) => self is Cause.Interrupt
isInterruptReason
/**
* Companion namespace for the `Cause` interface.
*
* @since 2.0.0
*/
export declare namespace Cause {
/**
* Extracts the error type `E` from a `Cause<E>`.
*
* **Example** (Extracting the error type)
*
* ```ts
* import type { Cause } from "effect"
*
* // string
* type E = Cause.Cause.Error<Cause.Cause<string>>
* ```
*
* @category models
* @since 4.0.0
*/
export type type Cause<out E>.Error<T> = T extends Cause<infer E> ? E : neverExtracts the error type E from a Cause<E>.
Example (Extracting the error type)
import type { Cause } from "effect"
// string
type E = Cause.Cause.Error<Cause.Cause<string>>
Error<function (type parameter) T in type Cause<out E>.Error<T>T> = function (type parameter) T in type Cause<out E>.Error<T>T extends 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<infer function (type parameter) EE> ? function (type parameter) EE : never
/**
* Base interface shared by all reason types (`Fail`, `Die`, `Interrupt`).
*
* **Details**
*
* Every reason carries:
* - `_tag` — discriminant string (`"Fail"`, `"Die"`, or `"Interrupt"`)
* - `annotations` — tracing metadata attached by the runtime
* - `annotate()` — returns a copy with additional annotations
*
* @category models
* @since 4.0.0
*/
export interface interface Cause<out E>.ReasonProto<Tag extends string>Base interface shared by all reason types (Fail, Die, Interrupt).
Details
Every reason carries:
_tag — discriminant string ("Fail", "Die", or "Interrupt")
annotations — tracing metadata attached by the runtime
annotate() — returns a copy with additional annotations
ReasonProto<function (type parameter) Tag in ReasonProto<Tag extends string>Tag extends string> extends Inspectable, Equal {
readonly [const ReasonTypeId: "~effect/Cause/Reason"Unique brand for Reason values, used for runtime type checks via
isReason
.
ReasonTypeId]: typeof const ReasonTypeId: "~effect/Cause/Reason"Unique brand for Reason values, used for runtime type checks via
isReason
.
ReasonTypeId
readonly Cause<out E>.ReasonProto<Tag extends string>._tag: Tag extends string_tag: function (type parameter) Tag in ReasonProto<Tag extends string>Tag
readonly Cause<out E>.ReasonProto<Tag extends string>.annotations: ReadonlyMap<string, unknown>annotations: interface ReadonlyMap<K, V>ReadonlyMap<string, unknown>
function Cause(annotations: Context.Context<never> | ReadonlyMap<string, unknown>, options?: { readonly overwrite?: boolean | undefined }): thisannotate(annotations: | Context.Context<never>
| ReadonlyMap<string, unknown>
annotations: import ContextContext.interface Context<in Services>Immutable collection of service implementations used for dependency
injection in Effect programs.
Details
The type parameter tracks the service identifiers available in the context.
At runtime, services are stored by each key's string key.
Example (Creating a context with multiple services)
import { Context } from "effect"
// Create a context with multiple services
const Logger = Context.Service<{ log: (msg: string) => void }>("Logger")
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
const context = Context.make(Logger, {
log: (msg: string) => console.log(msg)
})
.pipe(Context.add(Database, { query: (sql) => `Result: ${sql}` }))
Context<never> | interface ReadonlyMap<K, V>ReadonlyMap<string, unknown>, options: | {
readonly overwrite?: boolean | undefined
}
| undefined
options?: {
readonly overwrite?: boolean | undefinedoverwrite?: boolean | undefined
}): this
}
}
/**
* Companion namespace for the `Reason` type.
*
* @since 4.0.0
*/
export declare namespace Reason {
/**
* Extracts the error type `E` from a `Reason<E>`.
*
* **Example** (Extracting the error type)
*
* ```ts
* import type { Cause } from "effect"
*
* // string
* type E = Cause.Reason.Error<Cause.Reason<string>>
* ```
*
* @category models
* @since 4.0.0
*/
export type type Reason<E>.Error<T> = T extends Reason<infer E> ? E : neverExtracts the error type E from a Reason<E>.
Example (Extracting the error type)
import type { Cause } from "effect"
// string
type E = Cause.Reason.Error<Cause.Reason<string>>
Error<function (type parameter) T in type Reason<E>.Error<T>T> = function (type parameter) T in type Reason<E>.Error<T>T extends 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<infer function (type parameter) EE> ? function (type parameter) EE : never
}