---
id: fn-err
name: err
category: builtins
kind: builtin
tokens: err
sig: err(msg: string) -> result
tip: Wrap a failure message in a result — the sad half, recovered by try/else.
order: 13
---
Wraps a failure in a result, carrying a message that says what went wrong. It is the counterpart to ok: a fallible function (declared -> result) returns err("…") on the sad path instead of crashing or returning a magic sentinel. The caller recovers with try/else — the else block sees the message as error — or tests it with is_err. Unlike panic, which aborts, err is a value: the program keeps running and chooses a fallback.
Parameters:
- `msg` — a message describing the failure (a string)
```ludic
program Config {
function volume(pct: int) -> result {
if pct < 0 or pct > 100 { return err("volume out of range") }
return ok(pct)
}
test "err drives the fallback" {
let v = try volume(150) else { 100 } # clamp to a safe default
expect_eq(v, 100)
}
}
```