Hyperlinkv0.8.0-beta.28

Effect

Effect.tapCauseconsteffect/Effect.ts:3758
<E, X, E2, R2>(
  f: (cause: Cause.Cause<NoInfer<E>>) => Effect<X, E2, R2>
): <A, R>(self: Effect<A, E, R>) => Effect<A, E | E2, R2 | R>
<A, E, R, X, E2, R2>(
  self: Effect<A, E, R>,
  f: (cause: Cause.Cause<E>) => Effect<X, E2, R2>
): Effect<A, E | E2, R | R2>

Runs an effectful operation with the full Cause when the source effect fails.

When to use

Use when failure observation needs typed failures, defects, and interruptions rather than only the typed error value.

Details

Use this to log or inspect typed failures, defects, and interruptions. When the operation succeeds, the original cause is preserved. If the operation fails, its error is also represented in the returned effect.

Example (Observing full failure causes)

import { Cause, Console, Effect } from "effect"

const task = Effect.fail("Something went wrong")

const program = Effect.tapCause(
  task,
  (cause) => Console.log(`Logging cause: ${Cause.squash(cause)}`)
)

Effect.runPromiseExit(program).then(console.log)
// Output: "Logging cause: Error: Something went wrong"
// Then: { _id: 'Exit', _tag: 'Failure', cause: ... }
sequencing
Source effect/Effect.ts:37589 lines
export const tapCause: {
  <E, X, E2, R2>(
    f: (cause: Cause.Cause<NoInfer<E>>) => Effect<X, E2, R2>
  ): <A, R>(self: Effect<A, E, R>) => Effect<A, E | E2, R2 | R>
  <A, E, R, X, E2, R2>(
    self: Effect<A, E, R>,
    f: (cause: Cause.Cause<E>) => Effect<X, E2, R2>
  ): Effect<A, E | E2, R | R2>
} = internal.tapCause
Referenced by 4 symbols