<Effects extends StoreEffectsVariance<StoreContractValue>>(
effects: Effects
): CatchWriteError<Effects>Narrow StoreWriteError out of the error channel of a effects object's write
methods — a fire-and-forget append that fails a journal/IO write is logged and swallowed
(succeeds as void). One-liner over mapEffects. Composes with pipe:
pipe(Store.effects(scope, contract), Store.catchWriteErrors).
Scope of the guard, precisely:
- Write failures are swallowed — the
StoreWriteErroris caught, logged, and the effect completes successfully;StoreWriteErroris removed fromE(see CatchWriteError). - Defects are NOT swallowed — an encode/serialization mismatch (a bug: the value does not fit the declared shape, dies in the append path) and a wiring die (no store in context) are defects, not failures, so they propagate untouched.
- Reads and every other error are left exactly as-is —
Exclude<E, StoreWriteError>is a no-op whereStoreWriteErroris absent.
export const const catchWriteErrors: <
Effects extends StoreEffectsVariance<StoreContractValue>
>(
effects: Effects
) => CatchWriteError<Effects>
Narrow
StoreWriteError
out of the error channel of a
effects
object's write
methods — a fire-and-forget append that fails a journal/IO write is logged and swallowed
(succeeds as void). One-liner over
mapEffects
. Composes with pipe:
pipe(Store.effects(scope, contract), Store.catchWriteErrors).
Scope of the guard, precisely:
- Write failures are swallowed — the
StoreWriteError is caught, logged, and the effect
completes successfully; StoreWriteError is removed from E (see
CatchWriteError
).
- Defects are NOT swallowed — an encode/serialization mismatch (a bug: the value does not fit the
declared shape, dies in the append path) and a wiring die (no store in context) are defects,
not failures, so they propagate untouched.
- Reads and every other error are left exactly as-is —
Exclude<E, StoreWriteError> is a no-op
where StoreWriteError is absent.
catchWriteErrors = <function (type parameter) Effects in <Effects extends StoreEffectsVariance<StoreContractValue>>(effects: Effects): CatchWriteError<Effects>Effects extends interface StoreEffectsVariance<out C extends StoreContractValue>Variance carrier for the
effects
brand — mirrors Effect's Stream.Variance. C is
covariant (Effect's (_: never) => C encoding), so a specific contract's effects satisfy the wide
StoreEffectsVariance<StoreContractValue> constraint that
mapEffects
/
catchWriteErrors
take.
StoreEffectsVariance<import StoreContractValueStoreContractValue>>(
effects: Effects extends StoreEffectsVariance<StoreContractValue>effects: function (type parameter) Effects in <Effects extends StoreEffectsVariance<StoreContractValue>>(effects: Effects): CatchWriteError<Effects>Effects,
): type CatchWriteError<T> = T extends (
...args: infer A
) => Effect.Effect<infer S, infer E, infer R>
? (
...args: A
) => Effect.Effect<
S,
Exclude<E, StoreWriteError>,
R
>
: T extends Effect.Effect<
infer S,
infer E,
infer R
>
? Effect.Effect<
S,
Exclude<E, StoreWriteError>,
R
>
: T extends (
...args: ReadonlyArray<never>
) => unknown
? T
: T extends object
? {
readonly [K in keyof T]: CatchWriteError<
T[K]
>
}
: T
Remove
StoreWriteError
from the error channel of every method in a resolved-effects shape,
recursing into nested sub-trees — the per-method-precise result of
catchWriteErrors
. A write
method (...a) => Effect<S, StoreWriteError | E, R> → (...a) => Effect<S, E, R>; a read (whose E
lacks StoreWriteError) is unchanged (Exclude<E, StoreWriteError> is a no-op); the
StoreEffectsVariance
brand's non-effect members pass through (the function-passthrough branch
keeps _C intact).
CatchWriteError<function (type parameter) Effects in <Effects extends StoreEffectsVariance<StoreContractValue>>(effects: Effects): CatchWriteError<Effects>Effects> => const mapEffects: <
Effects extends StoreEffectsVariance<StoreContractValue>,
Out = Effects
>(
effects: Effects,
transform: (
effect: Effect.Effect<unknown, never, never>
) => Effect.Effect<unknown, never, never>
) => Out
The generic transform primitive: walk every method on a
effects
object (nested shape
leaves + custom methods) and pass each method's returned
Effect
through transform, then
re-nest and re-stamp the
TypeId
brand. Composes with pipe.
transform is applied uniformly; whether it changes types is expressed through the result:
- Type-preserving transforms (
withSpan / retry / timed, whose signature is
Effect<A, E, R> → Effect<A, E, R>) leave the type unchanged — Out defaults to Effects.
- Type-changing transforms (narrowing
E, like
catchWriteErrors
) supply an explicit
Out computed per method by a mapped type (e.g.
CatchWriteError
), so the change flows
through each method precisely.
mapEffects<function (type parameter) Effects in <Effects extends StoreEffectsVariance<StoreContractValue>>(effects: Effects): CatchWriteError<Effects>Effects, type CatchWriteError<T> = T extends (
...args: infer A
) => Effect.Effect<infer S, infer E, infer R>
? (
...args: A
) => Effect.Effect<
S,
Exclude<E, StoreWriteError>,
R
>
: T extends Effect.Effect<
infer S,
infer E,
infer R
>
? Effect.Effect<
S,
Exclude<E, StoreWriteError>,
R
>
: T extends (
...args: ReadonlyArray<never>
) => unknown
? T
: T extends object
? {
readonly [K in keyof T]: CatchWriteError<
T[K]
>
}
: T
Remove
StoreWriteError
from the error channel of every method in a resolved-effects shape,
recursing into nested sub-trees — the per-method-precise result of
catchWriteErrors
. A write
method (...a) => Effect<S, StoreWriteError | E, R> → (...a) => Effect<S, E, R>; a read (whose E
lacks StoreWriteError) is unchanged (Exclude<E, StoreWriteError> is a no-op); the
StoreEffectsVariance
brand's non-effect members pass through (the function-passthrough branch
keeps _C intact).
CatchWriteError<function (type parameter) Effects in <Effects extends StoreEffectsVariance<StoreContractValue>>(effects: Effects): CatchWriteError<Effects>Effects>>(effects: Effects extends StoreEffectsVariance<StoreContractValue>effects, const swallowWrite: (
effect: Effect.Effect<unknown, never, never>
) => Effect.Effect<unknown, never, never>
The
catchWriteErrors
write guard: swallow a
StoreWriteError
failure (log at
warning level, succeed as void), re-raise any other failure untouched, and leave defects alone
(Effect.catch recovers failures only — an encode/serialization mismatch or wiring die stays a
defect and propagates). A no-op on reads (they never fail with StoreWriteError).
swallowWrite);