Skip to main content

Overview

runPromiseUnwrapped is a convenience wrapper around Effect’s runPromiseExit that automatically throws errors in a more conventional format. Instead of wrapping errors in Effect’s Cause type, it directly throws the underlying error value.

Signature

Parameters

effect
Effect.Effect<A, E, never>
required
The Effect to execute. Must have no remaining service requirements (the R parameter must be never).

Returns

Returns a Promise<A> that:
  • Resolves with the success value if the Effect succeeds
  • Rejects with the error value (unwrapped from Cause) if the Effect fails
  • Rejects with the Cause itself if it’s not a standard failure (e.g., defects, interruptions)

Usage

Basic Success Case

Error Handling

Comparison with runPromiseExit

Here’s how runPromiseUnwrapped differs from using runPromiseExit directly:

Implementation Details

The function works by:
  1. Running the Effect with Effect.runPromiseExit
  2. Matching on the resulting Exit:
    • If success: return the value
    • If failure: check if it’s a standard failure (Cause.isFailType)
      • If yes: throw the unwrapped error
      • If no: throw the entire Cause (for defects, interruptions, etc.)
src/run-promise-unwrapped.ts

When to Use

Use runPromiseUnwrapped when integrating Effect code with traditional Promise-based code that expects standard error throwing behavior.

Good Use Cases

API Routes / HTTP Handlers
Test Utilities
Legacy Code Integration

When NOT to Use

Within Effect Code Inside an Effect context, use normal Effect error handling:
When You Need Structured Error Information If you need to distinguish between different failure types (defects, interruptions, failures), use runPromiseExit instead.

Error Types

The function handles different Cause types:

Standard Failures

Throws the unwrapped error:

Defects

Throws the entire Cause:

Interruptions

Throws the Cause:

See Also