@praha/byethrow
    Preparing search index...

    Function unwrapError

    • Extracts the error value from a Result, ResultAsync.

      If the result is a Success, it throws the success value (this is rare but symmetric to unwrap). For ResultAsync, it returns a Promise that resolves to the error value or rejects with the success value.

      Type Parameters

      Parameters

      Returns true extends HasPromise<R> ? Promise<InferFailure<R>> : InferFailure<R>

      The error value, or a Promise of the error value for async results.

      The success value if the result is a Success.

      import { Result } from '@praha/byethrow';

      const result: Result.Result<number, string> = Result.fail('Oops');
      const error = Result.unwrapError(result); // 'Oops'
      import { Result } from '@praha/byethrow';

      const result: Result.Result<number, string> = Result.succeed(100);
      const error = Result.unwrapError(result); // throws 100
      import { Result } from '@praha/byethrow';

      const result: Result.Result<number, string> = Result,fail(Promise.resolve('Oops'));
      const error = Result.unwrapError(result); // 'Oops'
      import { Result } from '@praha/byethrow';

      const result: Result.Result<number, string> = Result.succeed(Promise.resolve(100));
      const error = Result.unwrapError(result); // throws 100