(
annotations: Context.Context<never>,
options?: { readonly overwrite?: boolean | undefined }
): <E>(self: Cause<E>) => Cause<E>
<E>(
self: Cause<E>,
annotations: Context.Context<never>,
options?: { readonly overwrite?: boolean | undefined }
): Cause<E>Attaches metadata to every reason in a Cause.
When to use
Use to attach diagnostic metadata to every reason in a cause.
Details
Annotations are stored as a Context on each reason and can be
retrieved later via reasonAnnotations or annotations.
The runtime uses this to attach stack traces and spans.
- Returns a new
Cause. - By default, existing keys are preserved. Pass
{ overwrite: true }to replace them.
Example (Annotating a cause)
import { Cause, Context } from "effect"
class RequestId extends Context.Service<RequestId, string>()("RequestId") {}
const cause = Cause.fail("error")
const annotated = Cause.annotate(cause, Context.make(RequestId, "req-1"))
console.log(Context.getOrUndefined(Cause.annotations(annotated), RequestId)) // "req-1"export const const annotate: {
(
annotations: Context.Context<never>,
options?: {
readonly overwrite?: boolean | undefined
}
): <E>(self: Cause<E>) => Cause<E>
<E>(
self: Cause<E>,
annotations: Context.Context<never>,
options?: {
readonly overwrite?: boolean | undefined
}
): Cause<E>
}
Attaches metadata to every reason in a Cause.
When to use
Use to attach diagnostic metadata to every reason in a cause.
Details
Annotations are stored as a Context on each reason and can be
retrieved later via
reasonAnnotations
or
annotations
.
The runtime uses this to attach stack traces and spans.
- Returns a new
Cause.
- By default, existing keys are preserved. Pass
{ overwrite: true } to
replace them.
Example (Annotating a cause)
import { Cause, Context } from "effect"
class RequestId extends Context.Service<RequestId, string>()("RequestId") {}
const cause = Cause.fail("error")
const annotated = Cause.annotate(cause, Context.make(RequestId, "req-1"))
console.log(Context.getOrUndefined(Cause.annotations(annotated), RequestId)) // "req-1"
annotate: {
(
annotations: Context.Context<never>(parameter) annotations: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
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>,
options: | {
readonly overwrite?: boolean | undefined
}
| undefined
options?: { readonly overwrite?: boolean | undefinedoverwrite?: boolean | undefined }
): <function (type parameter) E in <E>(self: Cause<E>): Cause<E>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>): 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>(self: Cause<E>): Cause<E>E>
<function (type parameter) E in <E>(self: Cause<E>, annotations: Context.Context<never>, options?: {
readonly overwrite?: boolean | undefined;
}): Cause<E>
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>, annotations: Context.Context<never>, options?: {
readonly overwrite?: boolean | undefined;
}): Cause<E>
E>,
annotations: Context.Context<never>(parameter) annotations: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
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>,
options: | {
readonly overwrite?: boolean | undefined
}
| undefined
options?: { readonly overwrite?: boolean | undefinedoverwrite?: boolean | undefined }
): 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>, annotations: Context.Context<never>, options?: {
readonly overwrite?: boolean | undefined;
}): Cause<E>
E>
} = import corecore.const causeAnnotate: {
(
annotations: Context.Context<never>,
options?: {
readonly overwrite?: boolean | undefined
}
): <E>(self: Cause.Cause<E>) => Cause.Cause<E>
<E>(
self: Cause.Cause<E>,
annotations: Context.Context<never>,
options?: {
readonly overwrite?: boolean | undefined
}
): Cause.Cause<E>
}
causeAnnotate