function expect
expect<O>(
outcome: O,
message: string
): Exclude<O, Any>

Returns the success value, or throws new Error(message, { cause: failure }).

The counterpart to unwrap(): the thrown error's stack points here, at the code that demanded a value, while cause preserves the original failure and its own stack. Use it at the point where a failure stops being expected and becomes a bug.

A plain Error, deliberately — never a Failure: every Task consumer (result(), match, unwrapOr, recover) classifies a thrown Failure as declared and hands it onward as a value, so a Failure here would let an upstream boundary silently un-crash the bug this call just promoted. A plain Error can only travel to the crash boundary.

import * as Result from './index.ts';

import * as Config from '../setup/config.ts';

// Defined, not invoked: setup() assembles a real config. The doctest checks and
// evaluates the definition; only a caller would perform the work.
async function daemonBoot() {
  return Result.expect(await Config.setup().result(), 'daemon could not assemble its startup config');
}

Type Parameters

Parameters

outcome: O
message: string

Return Type

Exclude<O, Any>

Usage

import { expect } from "lib/result/result.ts";