RequiredErrorclass
new RequiredError(message?: string, options: BaseErrorOptions = {})| Param | Type | |
|---|---|---|
message | string | Optional human-readable description of what was required but missing. |
options | BaseErrorOptions | Options for BaseError that provide additional helpful error functionality. Defaults to {} |
.caller | AnyCaller | 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.
- Usually thrown from
requireX()functions, e.g.requireString()andrequireNumber().
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
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");