ValueErrorclass
new ValueError(message?: string, options: BaseErrorOptions = {})| Param | Type | |
|---|---|---|
message | string | Optional human-readable description of why the value is wrong. |
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 | |
|---|---|
ValueError | Thrown when a value is wrong or unexpected. |
Thrown when a value is wrong or unexpected.
- Use for invalid runtime values; pass
received/expectedviaoptionsfor context.
Thrown when a value was present but invalid in its context — for example data read from a database or an external source that failed validation. Pass the offending value as received so it appears in structured logs.
Usage
import { ValueError } from "shelving/error";
function parseConfig(raw: unknown): Config {
if (!isConfig(raw)) throw new ValueError("Invalid config from server", { received: raw });
return raw;
}See shelving/error for shared behaviour — attaching context fields, caller trimming, and catching by type.
Examples
throw new ValueError("Must be a positive number", { received: -1 });