Skip to content

error

Creates a failed ParseResult<T> containing one or more issue messages. This helper is the canonical way to construct failure results in safe parsers, validators, and other result‑producing helpers.

It never throws and never mutates input. When provided an array of issues, it always creates a defensive copy to ensure purity and prevent accidental mutation.

Signature

function error<T = never>(issues: string | string[]): ParseResult<T>

Parameters

Returns

A ParseResult<T> with: ok: false, value: null, issues: string[].

Behavior

  • Always returns a failure result.
  • Normalizes a single string into an array.
  • Creates a new array when given an array of issues.
  • Never throws and never mutates input.
  • Ensures value is always null in the failure branch.

Examples

error("Invalid input")
// { ok: false, value: null, issues: ["Invalid input"] }

error(["Missing field", "Invalid format"])
// { ok: false, value: null, issues: ["Missing field", "Invalid format"] }

Notes

  • The preferred way to construct failure results across the Jane ecosystem.
  • It ensures consistent structure and predictable behavior in all result‑based workflows.
  • Works seamlessly with ok, unwrap, unwrapOr, and safeTry.