<
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.type Effect.Effect = /*unresolved*/ anyEffect<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 Effect.Error = /*unresolved*/ anyError<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 Effect.Services = /*unresolved*/ anyServices<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.withFiber(import EffectEffect.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 <unknown>(iterable?: Iterable<unknown> | null | undefined) => Set<unknown> (+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.getRef(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: anyreporter of reporters: const Reporters extends ReadonlyArray<ErrorReporter | Effect.Effect<ErrorReporter, any, any>>reporters) {
const currentReporters: Set<ErrorReporter>currentReporters.Set<unknown>.add(value: unknown): Set<unknown>Appends a new element with a specified value to the end of the Set.
add(import EffectEffect.isEffect(const reporter: anyreporter) ? 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
}))
)