Hyperlinkv0.8.0-beta.28

Layer

Layer.tapErrorconsteffect/Layer.ts:1676
<E, XE extends E, RIn2, E2, X>(f: (e: XE) => Effect<X, E2, RIn2>): <
  RIn,
  ROut
>(
  self: Layer<ROut, E, RIn>
) => Layer<ROut, E | E2, RIn | Exclude<RIn2, Scope.Scope>>
<RIn, E, XE extends E, ROut, RIn2, E2, X>(
  self: Layer<ROut, E, RIn>,
  f: (e: XE) => Effect<X, E2, RIn2>
): Layer<ROut, E | E2, RIn | Exclude<RIn2, Scope.Scope>>

Performs the specified effect if this layer fails.

When to use

Use to run logging, metrics, or other effects when layer construction fails while preserving the original typed error.

Details

The callback receives the typed error. If the callback succeeds, the layer still fails with the original error; if the callback fails, that failure is added to the layer's error type.

sequencingtaptapCause
Source effect/Layer.ts:167618 lines
export const tapError: {
  <E, XE extends E, RIn2, E2, X>(
    f: (e: XE) => Effect<X, E2, RIn2>
  ): <RIn, ROut>(self: Layer<ROut, E, RIn>) => Layer<ROut, E | E2, RIn | Exclude<RIn2, Scope.Scope>>
  <RIn, E, XE extends E, ROut, RIn2, E2, X>(
    self: Layer<ROut, E, RIn>,
    f: (e: XE) => Effect<X, E2, RIn2>
  ): Layer<ROut, E | E2, RIn | Exclude<RIn2, Scope.Scope>>
} = dual(2, <RIn, E, XE extends E, ROut, RIn2, E2, X>(
  self: Layer<ROut, E, RIn>,
  f: (e: XE) => Effect<X, E2, RIn2>
): Layer<ROut, E | E2, RIn | Exclude<RIn2, Scope.Scope>> =>
  fromBuild((memoMap, scope) =>
    internalEffect.catch_(
      self.build(memoMap, scope),
      (error) => Scope.provide(internalEffect.andThen(f(error as XE), internalEffect.fail(error)), scope)
    )
  ))