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/isErr.md.

isErr

Type guard that narrows a Result to Err.

if (isErr(result)) {
  // result.error is Error
}

Usage

isErr(result)

The inverse of isOk. Useful when the failure path is the early-return: check isErr, bail, continue with the narrowed Ok after.

import { attemptAsync, isErr } from 'massaman'

const user = await attemptAsync(() => db.users.findById(id))
if (isErr(user)) {
  return respond.serverError(user.error)
}
// user is Ok<User> here
return respond.ok(user.value)

Parameters

resultResult<T>required

the result to test.

Returns

true if the result is a failure.

result is Err

See also