function
err
err(msg: string) -> result
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
msga message describing the failure (a string)Example
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)
}
}