@metreeca/core - v0.9.22
    Preparing search index...

    Function error

    • Throws an error in expression contexts.

      Reports a failure where a statement isn't allowed, for instance in a ternary branch, a nullish coalescing fallback, or the body of an arrow function; the call never returns and stands in for whatever type its position expects, so it composes with the surrounding expression without casts.

      Error causes are thrown as they are, preserving their type and stack trace; any other cause is wrapped in a generic Error reporting its string representation, so rejection reasons and other throwables of unknown type are surfaced as regular errors.

      Type Parameters

      • T

        The type the call stands in for at its use site; no value is ever returned

      Parameters

      • cause: unknown

        The Error to throw, or the value to report as the message of a new generic Error

      Returns T

      The cause argument, if it is an Error; otherwise a new Error reporting its string representation

      const port = ports.get(name) ?? error(`missing port <${name}>`);
      const value = isValid(input) ? input : error(new RangeError("invalid input"));
      const result = await task().catch(reason => error(reason)); // rethrow a reason of unknown type

      assert for validating a value against a predicate, throwing a TypeError if it fails