Hyperlinkv0.8.0-beta.28

Effect

Effect.sandboxconsteffect/Effect.ts:4160
<A, E, R>(self: Effect<A, E, R>): Effect<A, Cause.Cause<E>, R>

Exposes an effect's full failure cause in the error channel as Cause<E>.

Details

Use sandbox when downstream error handling needs to distinguish typed failures, defects, and interruptions. Use unsandbox to restore the original typed error channel after cause-level handling.

Example (Exposing failures as causes)

import { Cause, Effect } from "effect"

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

// Sandbox exposes the full cause as the error type
const program = Effect.gen(function*() {
  const result = yield* Effect.flip(Effect.sandbox(task))
  return `Caught cause: ${Cause.squash(result)}`
})

Effect.runPromise(program).then(console.log)
// Output: "Caught cause: Something went wrong"
error handling
Source effect/Effect.ts:41603 lines
export const sandbox: <A, E, R>(
  self: Effect<A, E, R>
) => Effect<A, Cause.Cause<E>, R> = internal.sandbox