RequiredErrorclass

new RequiredError(message?: string, options: BaseErrorOptions = {})
ParamType
messagestring
Optional human-readable description of what was required but missing.
optionsBaseErrorOptions
Options for BaseError that provide additional helpful error functionality. Defaults to {}
    .callerAnyCaller
Modify the stack to trim off lines after a certain calling function.
Return
RequiredError
Thrown when something is required but not supplied.

Thrown when something is required but not supplied.

Thrown when something required was absent — a missing argument, an empty lookup result, or an unset value. The require*() helpers — e.g. requireString() — throw this class.

Usage

ts
import { RequiredError } from "shelving/error";

function getUser(id: string | undefined): User {
  if (!id) throw new RequiredError("User ID is required");
  // ...
}

See shelving/error for shared behaviour — attaching context fields, caller trimming, and catching by type.

Examples

throw new RequiredError("Name is required");