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 createError or defineError when callers need typed custom data:
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 callcreateErroranddefineError— construct typed native errors- Result & Errors concept guide