createError
Constructs a standardized error result object used throughout Jane’s validation and normalization helpers. It is the canonical way to represent structured validation failures.
createError never throws and never mutates input. It simply wraps a field name and message into a predictable, intention‑revealing error result.
Signature
function createError(field: string, message: string): ErrorResult
Parameters
Returns
ErrorResult: { ok: false, field: string, message: string }
Behavior
- Pure function: no side effects.
- Never throws and never mutates input.
- Returns a new object on every call.
- Does not validate or coerce the provided values — it simply wraps them.
- Intended for use by validators, normalizers, and result helpers.
Examples
createError("username", "Username is required")
// { ok: false, field: "username", message: "Username is required" }
createError("age", "Must be a positive integer")
// { ok: false, field: "age", message: "Must be a positive integer" }
createError("", "")
// { ok: false, field: "", message: "" }
Notes
- Intentionally minimal. It does not enforce message formats or field naming conventions.
- It forms the structural foundation for all validation failures in Jane.
- Because it never throws, it is safe to use in any validation pipeline.
- Works seamlessly with Jane’s Result helpers (ok, error, unwrap, unwrapOr, safeTry).