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
The Effect to execute. Must have no remaining service requirements (the
R parameter must be never).Returns
Returns aPromise<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
Causeitself if it’s not a standard failure (e.g., defects, interruptions)
Usage
Basic Success Case
Error Handling
Comparison with runPromiseExit
Here’s howrunPromiseUnwrapped differs from using runPromiseExit directly:
Implementation Details
The function works by:- Running the Effect with
Effect.runPromiseExit - 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
Good Use Cases
✅ API Routes / HTTP HandlersWhen NOT to Use
❌ Within Effect Code Inside an Effect context, use normal Effect error handling:runPromiseExit instead.
Error Types
The function handles differentCause types:
Standard Failures
Throws the unwrapped error:Defects
Throws the entireCause:
Interruptions
Throws theCause:
See Also
- Effect.runPromiseExit - The underlying Effect function
- wrapClient - Uses similar error unwrapping for client wrappers
- oRPC Integration - Uses
runPromiseUnwrappedas a fallback