(
report: (options: {
readonly cause: Cause.Cause<unknown>
readonly error: Error
readonly attributes: ReadonlyRecord<string, unknown>
readonly severity: Severity
readonly fiber: Fiber.Fiber<unknown, unknown>
readonly timestamp: bigint
}) => void
): ErrorReporterCreates an ErrorReporter from a callback.
When to use
Use to define how reported failures are forwarded to a logging, monitoring, or error-tracking backend.
Details
The returned reporter automatically deduplicates causes and individual
errors (the same object is never reported twice), skips interruptions,
and resolves the ignore, severity, and attributes annotations on
each error before invoking your callback.
Example (Forwarding errors to the console)
import { ErrorReporter } from "effect"
// Forward every failure to the console
const consoleReporter = ErrorReporter.make(
({ error, severity, attributes }) => {
console.error(`[${severity}]`, error.message, attributes)
}
)export const const make: (
report: (options: {
readonly cause: Cause.Cause<unknown>
readonly error: Error
readonly attributes: ReadonlyRecord<
string,
unknown
>
readonly severity: Severity
readonly fiber: Fiber.Fiber<unknown, unknown>
readonly timestamp: bigint
}) => void
) => ErrorReporter
Creates an ErrorReporter from a callback.
When to use
Use to define how reported failures are forwarded to a logging, monitoring,
or error-tracking backend.
Details
The returned reporter automatically deduplicates causes and individual
errors (the same object is never reported twice), skips interruptions,
and resolves the ignore, severity, and attributes annotations on
each error before invoking your callback.
Example (Forwarding errors to the console)
import { ErrorReporter } from "effect"
// Forward every failure to the console
const consoleReporter = ErrorReporter.make(
({ error, severity, attributes }) => {
console.error(`[${severity}]`, error.message, attributes)
}
)
make = (
report: (options: {
readonly cause: Cause.Cause<unknown>
readonly error: Error
readonly attributes: ReadonlyRecord<
string,
unknown
>
readonly severity: Severity
readonly fiber: Fiber.Fiber<unknown, unknown>
readonly timestamp: bigint
}) => void
report: (options: {
readonly cause: Cause.Cause<unknown>
readonly error: Error
readonly attributes: ReadonlyRecord<
string,
unknown
>
readonly severity: Severity
readonly fiber: Fiber.Fiber<unknown, unknown>
readonly timestamp: bigint
}
options: {
readonly cause: Cause.Cause<unknown>(property) cause: {
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;
}
cause: import CauseCause.type Cause.Cause = /*unresolved*/ anyCause<unknown>
readonly error: Error(property) error: {
name: string;
message: string;
stack: string;
cause: unknown;
}
error: Error
readonly attributes: ReadonlyRecord<string, unknown>attributes: type ReadonlyRecord<in out K extends string | symbol, out A> = { readonly [P in K]: A; }Represents a readonly record with keys of type K and values of type A.
This is the foundational type for immutable key-value mappings in Effect.
Example (Defining a readonly record type)
import type { Record } from "effect"
// Creating a readonly record type
type UserRecord = Record.ReadonlyRecord<"name" | "age", string | number>
const user: UserRecord = {
name: "John",
age: 30
}
Namespace containing utility types for working with readonly records.
These types help with type-level operations on record keys and values.
Example (Using readonly record helper types)
import type { Record } from "effect"
// Using NonLiteralKey to convert literal keys to generic types
type GenericKey = Record.ReadonlyRecord.NonLiteralKey<"foo" | "bar"> // string
// Using IntersectKeys to find common keys between record types
type CommonKeys = Record.ReadonlyRecord.IntersectKeys<"a" | "b", "b" | "c"> // "b"
ReadonlyRecord<string, unknown>
readonly severity: Severityseverity: type Severity = "Fatal" | "Error" | "Warn" | "Info" | "Debug" | "Trace"Log levels that represent actual message severities, excluding the All and
None sentinel levels.
When to use
Use when typing emitted log message severities, such as explicit log calls,
current log level references, or error-report severity annotations, where
All and None are not valid values.
Severity
readonly fiber: Fiber.Fiber<unknown, unknown>(property) fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | undefined;
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; <…;
}
fiber: import FiberFiber.interface Fiber<out A, out E = never>A runtime fiber is a lightweight thread that executes Effects. Fibers are
the unit of concurrency in Effect. They provide a way to run multiple
Effects concurrently while maintaining structured concurrency and
cancellation safety.
When to use
Use to observe, join, interrupt, or coordinate work that has already been
forked.
Details
A fiber exposes both safe Effect-based operations, such as
await
,
join
, and
interrupt
, and low-level runtime fields used by
the scheduler and runtime internals.
Gotchas
Prefer the exported functions in this module over calling interruptUnsafe
or pollUnsafe directly. The unsafe methods are immediate runtime hooks and
do not provide the same Effect-based sequencing guarantees.
Example (Awaiting a forked fiber)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Fork an effect to run in a new fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Wait for the fiber to complete and get its result
const result = yield* Fiber.await(fiber)
console.log(result) // Exit.succeed(42)
return result
})
The Fiber namespace contains utility types and functions for working with fibers.
It provides type-level utilities for fiber operations and variance encoding.
When to use
Use to reference type-level helpers associated with Fiber.
Details
The namespace currently exposes type-level support used by the Fiber
interface. Runtime operations are exported as module-level functions.
Example (Working with fiber types)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Create a fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Use namespace types for variance
const typedFiber: Fiber.Fiber<number, never> = fiber
// Access fiber properties
console.log(`Fiber ID: ${fiber.id}`)
// Join the fiber
const result = yield* Fiber.join(fiber)
return result // 42
})
Fiber<unknown, unknown>
readonly timestamp: biginttimestamp: bigint
}) => void
): ErrorReporter => {
const const reported: WeakSet<any>reported = new var WeakSet: WeakSetConstructor
new <any>(values?: readonly any[] | null | undefined) => WeakSet<any> (+1 overload)
WeakSet<import CauseCause.type Cause.Cause = /*unresolved*/ anyCause<unknown> | object>()
return {
[const TypeId: TypeIdString literal type used as the runtime type identifier for
ErrorReporter values.
When to use
Use to refer to the runtime type identifier type in low-level integrations.
Runtime type identifier attached to ErrorReporter values.
Details
This marker is part of the runtime representation of ErrorReporter
implementations. Most code should create reporters with make and register
them with layer.
TypeId]: const TypeId: TypeIdString literal type used as the runtime type identifier for
ErrorReporter values.
When to use
Use to refer to the runtime type identifier type in low-level integrations.
Runtime type identifier attached to ErrorReporter values.
Details
This marker is part of the runtime representation of ErrorReporter
implementations. Most code should create reporters with make and register
them with layer.
TypeId,
ErrorReporter.report(options: { readonly cause: Cause.Cause<unknown>; readonly fiber: Fiber.Fiber<unknown, unknown>; readonly timestamp: bigint }): voidreport(options: {
readonly cause: Cause.Cause<unknown>
readonly fiber: Fiber.Fiber<unknown, unknown>
readonly timestamp: bigint
}
options) {
if (const reported: WeakSet<any>reported.WeakSet<any>.has(value: any): booleanhas(options: {
readonly cause: Cause.Cause<unknown>
readonly fiber: Fiber.Fiber<unknown, unknown>
readonly timestamp: bigint
}
options.cause: Cause.Cause<unknown>(property) cause: {
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;
}
cause)) return
const reported: WeakSet<any>reported.WeakSet<any>.add(value: any): WeakSet<any>Appends a new value to the end of the WeakSet.
add(options: {
readonly cause: Cause.Cause<unknown>
readonly fiber: Fiber.Fiber<unknown, unknown>
readonly timestamp: bigint
}
options.cause: Cause.Cause<unknown>(property) cause: {
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;
}
cause)
for (let let i: numberi = 0; let i: numberi < options: {
readonly cause: Cause.Cause<unknown>
readonly fiber: Fiber.Fiber<unknown, unknown>
readonly timestamp: bigint
}
options.cause: Cause.Cause<unknown>(property) cause: {
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;
}
cause.reasons.length; let i: numberi++) {
const const reason: Cause.Reason<unknown>reason = options: {
readonly cause: Cause.Cause<unknown>
readonly fiber: Fiber.Fiber<unknown, unknown>
readonly timestamp: bigint
}
options.cause: Cause.Cause<unknown>(property) cause: {
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;
}
cause.reasons[let i: numberi]
if (const reason: Cause.Reason<unknown>reason._tag === "Interrupt") continue
const const original: anyoriginal = const reason: anyreason._tag === "Fail" ? const reason: Cause.Fail<unknown>const reason: {
error: E;
_tag: Tag;
annotations: ReadonlyMap<string, unknown>;
annotate: (annotations: Context.Context<never> | ReadonlyMap<string, unknown>, options?: { readonly overwrite?: boolean | undefined }) => Cause.Fail<unknown>;
toString: () => string;
toJSON: () => unknown;
}
reason.error : const reason: Cause.Dieconst reason: {
defect: unknown;
_tag: Tag;
annotations: ReadonlyMap<string, unknown>;
annotate: (annotations: Context.Context<never> | ReadonlyMap<string, unknown>, options?: { readonly overwrite?: boolean | undefined }) => Cause.Die;
toString: () => string;
toJSON: () => unknown;
}
reason.defect
const const isObject: booleanisObject = typeof const original: anyoriginal === "object" && const original: anyoriginal !== null
if (const isObject: booleanisObject) {
if (const reported: WeakSet<any>reported.WeakSet<any>.has(value: any): booleanhas(const original: anyoriginal)) continue
const reported: WeakSet<any>reported.WeakSet<any>.add(value: any): WeakSet<any>Appends a new value to the end of the WeakSet.
add(const original: anyoriginal)
}
if (const isIgnored: (u: unknown) => booleanReturns true if the given value has the ErrorReporter.ignore annotation
set to true.
When to use
Use to check whether an error value is annotated to be skipped before
forwarding it to error reporting code.
isIgnored(const original: anyoriginal)) continue
const const pretty: Errorconst pretty: {
name: string;
message: string;
stack: string;
cause: unknown;
}
pretty = import effecteffect.const causePrettyError: (
original: Record<string, unknown> | Error,
annotations?: ReadonlyMap<string, unknown>,
options?: {
readonly includeCauseInStack?:
| boolean
| undefined
}
) => Error
causePrettyError(const original: anyoriginal as any, const reason: anyreason.annotations)
report: (options: {
readonly cause: Cause.Cause<unknown>
readonly error: Error
readonly attributes: ReadonlyRecord<
string,
unknown
>
readonly severity: Severity
readonly fiber: Fiber.Fiber<unknown, unknown>
readonly timestamp: bigint
}) => void
report({
...options: {
readonly cause: Cause.Cause<unknown>
readonly fiber: Fiber.Fiber<unknown, unknown>
readonly timestamp: bigint
}
options,
error: Error(property) error: {
name: string;
message: string;
stack: string;
cause: unknown;
}
error: const pretty: Errorconst pretty: {
name: string;
message: string;
stack: string;
cause: unknown;
}
pretty,
severity: LogLevel.Severityseverity: const isObject: booleanisObject ? const getSeverity: (
error: object
) => Severity
Reads the ErrorReporter.severity annotation from an error object,
falling back to "Info" when the annotation is unset or invalid.
When to use
Use to inspect the severity that reporter callbacks will receive for an
object error.
getSeverity(const original: anyoriginal) : "Info",
attributes: ReadonlyRecord<string, unknown>attributes: const isObject: booleanisObject ? const getAttributes: (
error: object
) => ReadonlyRecord<string, unknown>
Reads the ErrorReporter.attributes annotation from an error object,
returning an empty record when unset.
When to use
Use to inspect the attributes that reporter callbacks will receive for an
object error.
Details
Returns the value stored under ErrorReporter.attributes, or the module's
shared empty record when the annotation is absent.
Gotchas
The annotation value is returned as-is; this helper does not validate or
clone it.
getAttributes(const original: anyoriginal) : const emptyAttributes: ReadonlyRecord<
string,
unknown
>
emptyAttributes
})
}
}
}
}