UNPKG

option-t

Version:

A toolkit of Nullable/Option/Result type implementation in ECMAScript. Their APIs are inspired by Rust's `Option<T>` and `Result<T, E>`.

36 lines (35 loc) 1.43 kB
import { isOk } from '../core/result.js'; import { unsafeUnwrapValueInErrWithoutAnyCheck, unsafeUnwrapValueInOkWithoutAnyCheck, } from '../internal/intrinsics_unsafe.js'; /** * @deprecated 48.1.0 * This operator throws the `Error` contained in _input_ directly * but its stack trace informartion lacks the information about where throws it actually. * To keep it, use `unwrapOrThrowForResult` exported from following instead: * * - `option-t/plain_result` * - `option-t/plain_result/unwrap_or_throw` * - `option-t/plain_result/namespace` exports it as `Result.unwrapOrThrow()` * * It throw a new `Error` with keeping the original error as `Error.cause` property. * * ------- * * Unwraps _input_, returns the content of an `Ok(T)`. * Otherwise, this function throw the contained `unknown` __directly__ in `Err(unknown)`. * * __We DO NOT RECCOMEND TO USE THIS function generally__. * * This function is provided only to improve an interoperability with the world using "throw error" convention. * __We do not recommend to use this function__. * * @throws {unknown} * This throws an inner value wrapped by Err(unknown)` __directly__. */ export function unwrapOrThrowUnknownDirectlyForResult(input) { if (isOk(input)) { const val = unsafeUnwrapValueInOkWithoutAnyCheck(input); return val; } const e = unsafeUnwrapValueInErrWithoutAnyCheck(input); throw e; }