<
const Reporters extends ReadonlyArray<
ErrorReporter | Effect.Effect<ErrorReporter, any, any>
>
>(
reporters: Reporters,
options?:
| { readonly mergeWithExisting?: boolean | undefined }
| undefined
): Layer.Layer<
never,
Reporters extends readonly [] ? never : Effect.Error<Reporters[number]>,
Exclude<
Reporters extends readonly []
? never
: Effect.Services<Reporters[number]>,
Scope.Scope
>
>Creates a Layer that registers one or more ErrorReporters.
When to use
Use to provide one or more error reporters to effects that perform error reporting.
Details
Reporters can be plain ErrorReporter values or effectful
Effect<ErrorReporter> values that are resolved when the layer is built. By
default the provided reporters replace any previously registered
reporters. Set mergeWithExisting: true to add them alongside existing ones.
Example (Providing error reporters)
import { Effect, ErrorReporter } from "effect"
const consoleReporter = ErrorReporter.make(({ error, severity }) => {
console.error(`[${severity}]`, error.message)
})
const metricsReporter = ErrorReporter.make(({ severity }) => {
// increment an error counter by severity
})
// Replace all existing reporters
const ReporterLive = ErrorReporter.layer([
consoleReporter,
metricsReporter
])
// Add to existing reporters instead of replacing
const ReporterMerged = ErrorReporter.layer(
[metricsReporter],
{ mergeWithExisting: true }
)
const program = Effect.fail("boom").pipe(
Effect.withErrorReporting,
Effect.provide(ReporterLive)
)export const const layer: <
Reporters extends ReadonlyArray<
| ErrorReporter
| Effect.Effect<ErrorReporter, any, any>
>
>(
reporters: Reporters,
options?:
| {
readonly mergeWithExisting?:
| boolean
| undefined
}
| undefined
) => Layer.Layer<
never,
Reporters extends readonly []
? never
: Effect.Error<Reporters[number]>,
Exclude<
Reporters extends readonly []
? never
: Effect.Services<Reporters[number]>,
Scope.Scope
>
>
Creates a Layer that registers one or more ErrorReporters.
When to use
Use to provide one or more error reporters to effects that perform error
reporting.
Details
Reporters can be plain ErrorReporter values or effectful
Effect<ErrorReporter> values that are resolved when the layer is built. By
default the provided reporters replace any previously registered
reporters. Set mergeWithExisting: true to add them alongside existing ones.
Example (Providing error reporters)
import { Effect, ErrorReporter } from "effect"
const consoleReporter = ErrorReporter.make(({ error, severity }) => {
console.error(`[${severity}]`, error.message)
})
const metricsReporter = ErrorReporter.make(({ severity }) => {
// increment an error counter by severity
})
// Replace all existing reporters
const ReporterLive = ErrorReporter.layer([
consoleReporter,
metricsReporter
])
// Add to existing reporters instead of replacing
const ReporterMerged = ErrorReporter.layer(
[metricsReporter],
{ mergeWithExisting: true }
)
const program = Effect.fail("boom").pipe(
Effect.withErrorReporting,
Effect.provide(ReporterLive)
)
layer = <
const function (type parameter) Reporters in <const Reporters extends ReadonlyArray<ErrorReporter | Effect.Effect<ErrorReporter, any, any>>>(reporters: Reporters, options?: {
readonly mergeWithExisting?: boolean | undefined;
} | undefined): Layer.Layer<never, Reporters extends readonly [] ? never : Effect.Error<Reporters[number]>, Exclude<Reporters extends readonly [] ? never : Effect.Services<Reporters[number]>, Scope.Scope>>
Reporters extends interface ReadonlyArray<T>ReadonlyArray<ErrorReporter | import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<ErrorReporter, any, any>>
>(
reporters: const Reporters extends ReadonlyArray<ErrorReporter | Effect.Effect<ErrorReporter, any, any>>reporters: function (type parameter) Reporters in <const Reporters extends ReadonlyArray<ErrorReporter | Effect.Effect<ErrorReporter, any, any>>>(reporters: Reporters, options?: {
readonly mergeWithExisting?: boolean | undefined;
} | undefined): Layer.Layer<never, Reporters extends readonly [] ? never : Effect.Error<Reporters[number]>, Exclude<Reporters extends readonly [] ? never : Effect.Services<Reporters[number]>, Scope.Scope>>
Reporters,
options: | {
readonly mergeWithExisting?:
| boolean
| undefined
}
| undefined
options?: { readonly mergeWithExisting?: boolean | undefinedmergeWithExisting?: boolean | undefined } | undefined
): import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<
never,
function (type parameter) Reporters in <const Reporters extends ReadonlyArray<ErrorReporter | Effect.Effect<ErrorReporter, any, any>>>(reporters: Reporters, options?: {
readonly mergeWithExisting?: boolean | undefined;
} | undefined): Layer.Layer<never, Reporters extends readonly [] ? never : Effect.Error<Reporters[number]>, Exclude<Reporters extends readonly [] ? never : Effect.Services<Reporters[number]>, Scope.Scope>>
Reporters extends readonly [] ? never : import EffectEffect.type Error<T> = T extends Effect.Effect<
infer _A,
infer _E,
infer _R
>
? _E
: never
Extracts the error type from an Effect.
When to use
Use to derive the error type from an existing Effect type when declaring
helper types, wrappers, or APIs that preserve the effect's failure channel.
Details
Non-Effect inputs resolve to never.
Error<function (type parameter) Reporters in <const Reporters extends ReadonlyArray<ErrorReporter | Effect.Effect<ErrorReporter, any, any>>>(reporters: Reporters, options?: {
readonly mergeWithExisting?: boolean | undefined;
} | undefined): Layer.Layer<never, Reporters extends readonly [] ? never : Effect.Error<Reporters[number]>, Exclude<Reporters extends readonly [] ? never : Effect.Services<Reporters[number]>, Scope.Scope>>
Reporters[number]>,
type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<
function (type parameter) Reporters in <const Reporters extends ReadonlyArray<ErrorReporter | Effect.Effect<ErrorReporter, any, any>>>(reporters: Reporters, options?: {
readonly mergeWithExisting?: boolean | undefined;
} | undefined): Layer.Layer<never, Reporters extends readonly [] ? never : Effect.Error<Reporters[number]>, Exclude<Reporters extends readonly [] ? never : Effect.Services<Reporters[number]>, Scope.Scope>>
Reporters extends readonly [] ? never : import EffectEffect.type Services<T> =
T extends Effect.Effect<
infer _A,
infer _E,
infer _R
>
? _R
: never
Extracts the required services type from an Effect.
When to use
Use to derive the context requirements of a generic or inferred Effect
without restating its R type parameter.
Services<function (type parameter) Reporters in <const Reporters extends ReadonlyArray<ErrorReporter | Effect.Effect<ErrorReporter, any, any>>>(reporters: Reporters, options?: {
readonly mergeWithExisting?: boolean | undefined;
} | undefined): Layer.Layer<never, Reporters extends readonly [] ? never : Effect.Error<Reporters[number]>, Exclude<Reporters extends readonly [] ? never : Effect.Services<Reporters[number]>, Scope.Scope>>
Reporters[number]>,
import ScopeScope.Scope
>
> =>
import LayerLayer.const effect: {
<I, S>(service: Context.Key<I, S>): <E, R>(
effect: Effect<S, E, R>
) => Layer<I, E, Exclude<R, Scope.Scope>>
<I, S, E, R>(
service: Context.Key<I, S>,
effect: Effect<Types.NoInfer<S>, E, R>
): Layer<I, E, Exclude<R, Scope.Scope>>
}
effect(
const CurrentErrorReporters: Context.Reference<
ReadonlySet<ErrorReporter>
>
const CurrentErrorReporters: {
key: string;
Service: {
forEach: (callbackfn: (value: ErrorReporter, value2: ErrorReporter, set: ReadonlySet<ErrorReporter>) => void, thisArg?: any) => void;
has: (value: ErrorReporter) => boolean;
size: number;
entries: () => SetIterator<[ErrorReporter, ErrorReporter]>;
keys: () => SetIterator<ErrorReporter>;
values: () => SetIterator<ErrorReporter>;
union: (other: ReadonlySetLike<U>) => Set<ErrorReporter | U>;
intersection: (other: ReadonlySetLike<U>) => Set<ErrorReporter & U>;
difference: (other: ReadonlySetLike<U>) => Set<ErrorReporter>;
symmetricDifference: (other: ReadonlySetLike<U>) => Set<ErrorReporter | U>;
isSubsetOf: (other: ReadonlySetLike<unknown>) => boolean;
isSupersetOf: (other: ReadonlySetLike<unknown>) => boolean;
isDisjointFrom: (other: ReadonlySetLike<unknown>) => boolean;
};
defaultValue: () => Shape;
of: (this: void, self: ReadonlySet<ErrorReporter>) => ReadonlySet<ErrorReporter>;
context: (self: ReadonlySet<ErrorReporter>) => Context.Context<never>;
use: (f: (service: ReadonlySet<ErrorReporter>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
useSync: (f: (service: ReadonlySet<ErrorReporter>) => A) => Effect.Effect<A, never, never>;
Identifier: Identifier;
stack: string | 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; <…;
toString: () => string;
toJSON: () => unknown;
}
Context reference that holds the set of active error reporters for the
current fiber. Defaults to an empty set (no reporting).
When to use
Use when you need to read or replace the current set of error reporters
directly.
CurrentErrorReporters,
import EffectEffect.const withFiber: <
A,
E = never,
R = never
>(
evaluate: (
fiber: Fiber<unknown, unknown>
) => Effect<A, E, R>
) => Effect<A, E, R>
Provides access to the current fiber within an effect computation.
Example (Reading the current fiber)
import { Effect } from "effect"
const program = Effect.withFiber((fiber) =>
Effect.succeed(`Fiber ID: ${fiber.id}`)
)
Effect.runPromise(program).then(console.log)
// Output: Fiber ID: 1
withFiber(import EffectEffect.const fnUntraced: <Effect.Effect<ErrorReporter, any, any>, Set<ErrorReporter>, [fiber: Fiber.Fiber<unknown, unknown>]>(body: (this: unassigned, fiber: Fiber.Fiber<unknown, unknown>) => Generator<Effect.Effect<ErrorReporter, any, any>, Set<ErrorReporter>, never>) => (fiber: Fiber.Fiber<unknown, unknown>) => Effect.Effect<Set<ErrorReporter>, any, any> (+41 overloads)fnUntraced(function*(fiber: Fiber.Fiber<unknown, unknown>(parameter) 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) {
const const currentReporters: Set<ErrorReporter>currentReporters = new var Set: SetConstructor
new <ErrorReporter>(iterable?: Iterable<ErrorReporter> | null | undefined) => Set<ErrorReporter> (+1 overload)
Set(
options: | {
readonly mergeWithExisting?:
| boolean
| undefined
}
| undefined
options?.mergeWithExisting?: boolean | undefinedmergeWithExisting === true ? fiber: Fiber.Fiber<unknown, unknown>(parameter) 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.Fiber<unknown, unknown>.getRef: <A>(ref: Context.Reference<A>) => AgetRef(import referencesreferences.const CurrentErrorReporters: Context.Reference<
ReadonlySet<ErrorReporter>
>
const CurrentErrorReporters: {
key: string;
Service: {
forEach: (callbackfn: (value: ErrorReporter, value2: ErrorReporter, set: ReadonlySet<ErrorReporter>) => void, thisArg?: any) => void;
has: (value: ErrorReporter) => boolean;
size: number;
entries: () => SetIterator<[ErrorReporter, ErrorReporter]>;
keys: () => SetIterator<ErrorReporter>;
values: () => SetIterator<ErrorReporter>;
union: (other: ReadonlySetLike<U>) => Set<ErrorReporter | U>;
intersection: (other: ReadonlySetLike<U>) => Set<ErrorReporter & U>;
difference: (other: ReadonlySetLike<U>) => Set<ErrorReporter>;
symmetricDifference: (other: ReadonlySetLike<U>) => Set<ErrorReporter | U>;
isSubsetOf: (other: ReadonlySetLike<unknown>) => boolean;
isSupersetOf: (other: ReadonlySetLike<unknown>) => boolean;
isDisjointFrom: (other: ReadonlySetLike<unknown>) => boolean;
};
defaultValue: () => Shape;
of: (this: void, self: ReadonlySet<ErrorReporter>) => ReadonlySet<ErrorReporter>;
context: (self: ReadonlySet<ErrorReporter>) => Context.Context<never>;
use: (f: (service: ReadonlySet<ErrorReporter>) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
useSync: (f: (service: ReadonlySet<ErrorReporter>) => A) => Effect.Effect<A, never, never>;
Identifier: Identifier;
stack: string | 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; <…;
toString: () => string;
toJSON: () => unknown;
}
CurrentErrorReporters) : []
)
for (const const reporter:
| ErrorReporter
| Effect.Effect<ErrorReporter, any, any>
reporter of reporters: const Reporters extends ReadonlyArray<ErrorReporter | Effect.Effect<ErrorReporter, any, any>>reporters) {
const currentReporters: Set<ErrorReporter>currentReporters.Set<ErrorReporter>.add(value: ErrorReporter): Set<ErrorReporter>Appends a new element with a specified value to the end of the Set.
add(import EffectEffect.const isEffect: (
u: unknown
) => u is Effect<any, any, any>
Checks whether a value is an Effect.
Example (Checking whether a value is an Effect)
import { Effect } from "effect"
console.log(Effect.isEffect(Effect.succeed(1))) // true
console.log(Effect.isEffect("hello")) // false
isEffect(const reporter:
| ErrorReporter
| Effect.Effect<ErrorReporter, any, any>
reporter) ? yield* const reporter: Effect.Effect<
ErrorReporter,
any,
any
>
const reporter: {
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;
}
reporter : const reporter: ErrorReporterconst reporter: {
report: (options: { readonly cause: Cause.Cause<unknown>; readonly fiber: Fiber.Fiber<unknown, unknown>; readonly timestamp: bigint }) => void;
}
reporter)
}
return const currentReporters: Set<ErrorReporter>currentReporters
}))
)