API reference › @evolu/common › Result › getOrThrow
function getOrThrow<T, E>(result: Result<T, E>): T;
Defined in: packages/common/src/Result.ts:351
Returns the value from an Ok Result, or throws if it is an Err.
Use this where failure should crash the current flow instead of being handled locally.
When to use:
- Application startup or composition-root setup where errors must stop the
program immediately. In Evolu apps, errors are handled by platform-specific
createRunadapters at the app boundary. - Module-level constants
- Test setup with values that are expected to be valid
Prefer an explicit if (!result.ok) check in ordinary application logic
where the caller can recover, retry, or choose a different flow.
Example
// At app startup, crash if config is invalid:
const config = getOrThrow(loadConfig());
// Safe to use config here
Throws: Error with the original error attached as cause.