<E>(self: Reason<E>): Context.Context<never>Reads the annotations from a single Reason as a Context.
When to use
Use when you need tracing metadata (e.g. StackTrace) from
a specific reason rather than the whole cause.
Example (Reading reason annotations)
import { Cause, Context } from "effect"
class RequestId extends Context.Service<RequestId, string>()("RequestId") {}
const reason = Cause.makeFailReason("error")
const annotated = reason.annotate(Context.make(RequestId, "req-1"))
console.log(Context.getOrUndefined(Cause.reasonAnnotations(annotated), RequestId)) // "req-1"export const const reasonAnnotations: <E>(
self: Reason<E>
) => Context.Context<never>
Reads the annotations from a single Reason as a Context.
When to use
Use when you need tracing metadata (e.g. StackTrace) from
a specific reason rather than the whole cause.
Example (Reading reason annotations)
import { Cause, Context } from "effect"
class RequestId extends Context.Service<RequestId, string>()("RequestId") {}
const reason = Cause.makeFailReason("error")
const annotated = reason.annotate(Context.make(RequestId, "req-1"))
console.log(Context.getOrUndefined(Cause.reasonAnnotations(annotated), RequestId)) // "req-1"
reasonAnnotations: <function (type parameter) E in <E>(self: Reason<E>): Context.Context<never>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>): 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 reasonAnnotations: <E>(
self: Cause.Reason<E>
) => Context.Context<never>
reasonAnnotations