For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/control/err.md.

err

Constructs a failure Result. Normalizes any thrown value into an Error.

const result = err(reason)

Usage

err(reason)

Pass an Error, a string, or any other value. 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.

import { err } from 'massaman'

err(new Error('boom'))
// { ok: false, value: null, error: Error('boom') }

err('division by zero')
// { ok: false, value: null, error: Error('division by zero') }

err({ code: 'EBADF', fd: 3 })
// { ok: false, value: null, error: Error('{"code":"EBADF","fd":3}', { cause: { code: 'EBADF', fd: 3 } }) }

Parameters

reasonunknownrequired

the failure value. Accepts anything — normalization to Error is the function's job.

Returns

{ ok: false, value: null, error: Error }.

Err

See also