<E>(self: Cause<E>): Context.Context<never>Reads the merged annotations from all reasons in a Cause.
When to use
Use to read diagnostic metadata merged from the whole cause.
Gotchas
When multiple reasons contain the same annotation key, the value from the later reason wins.
Example (Reading merged annotations)
import { Cause, Context } from "effect"
class RequestId extends Context.Service<RequestId, string>()("RequestId") {}
const cause = Cause.annotate(
Cause.fail("error"),
Context.make(RequestId, "req-1")
)
console.log(Context.getOrUndefined(Cause.annotations(cause), RequestId)) // "req-1"export const const annotations: <E>(
self: Cause<E>
) => Context.Context<never>
Reads the merged annotations from all reasons in a Cause.
When to use
Use to read diagnostic metadata merged from the whole cause.
Gotchas
When multiple reasons contain the same annotation key, the value from the
later reason wins.
Example (Reading merged annotations)
import { Cause, Context } from "effect"
class RequestId extends Context.Service<RequestId, string>()("RequestId") {}
const cause = Cause.annotate(
Cause.fail("error"),
Context.make(RequestId, "req-1")
)
console.log(Context.getOrUndefined(Cause.annotations(cause), RequestId)) // "req-1"
annotations: <function (type parameter) E in <E>(self: Cause<E>): Context.Context<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>): Context.Context<never>E>) => 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> = import effecteffect.const causeAnnotations: <E>(
self: Cause.Cause<E>
) => Context.Context<never>
causeAnnotations