effect-io-ai

Package: effect
Module: Cause

Cause.annotate

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.

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"

See

Signature

declare 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>; }

Source

Since v4.0.0