err
Constructs a failure Result. Preserves specific Error types and normalizes non-Error values into Error.
Usage
err(reason)
Pass an Error, a string, or any other value. Error instances are returned unchanged, including their specific subtype. Strings are wrapped in new Error(reason). Non-error, non-string values get JSON.stringify'd into the message and the original is preserved on error.cause.
Use a typed Error when callers need to map domain failures to HTTP responses:
Parameters
reasonunknownrequired
the failure value. Accepts anything — normalization to Error is the function's job.
Returns
Err<E> when given E extends Error; otherwise Err<Error>.
See also
ok— construct a success resultattempt— wrap an unsafe call- Result & Errors concept guide