effect-io-ai

Package: effect
Module: Effect

Effect.sandbox

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"

Signature

declare const sandbox: <A, E, R>(self: Effect<A, E, R>) => Effect<A, Cause.Cause<E>, R>

Source

Since v2.0.0