Result System — pass and fail
Overview
Inside regular functions (not main or failsafe), use pass and fail to return
Results:
pass value— return success Result containing valuefail errcode— return error Result with the currentint32runtime error code
See
guide/result/for the canonical v0.33.6 Result handling cookbook.
Pass
func:square = int32(int32:x) {
pass (x * x);
};
func:greet = NIL(string:name) {
println(`Hello, &{name}!`);
pass(NIL); // NIL-returning functions must pass NIL
};
pass wraps the value in Result<T>{value=val, error=NIL, is_error=false}.
Fail
func:divide = flt64(int32:a, int32:b) {
if (b == 0) {
fail 1; // error code 1 — division by zero
}
pass (a / b);
};
fail wraps the error code in Result<T>{value=<zero/NIL-shaped>, error=code, is_error=true}.
Paren Syntax
Both support optional parentheses (v0.4.6+):
pass(42); // same as: pass 42;
fail(1); // same as: fail 1;
pass (x * x); // parenthesized expression (always worked)
return Keyword
return is also available and expects a full Result<T> instance:
return Result{ error: err, value: NIL, is_error: true };
In practice, pass/fail are preferred — they're more concise.
Related
- result/ — canonical Result handling cookbook
- types/result.md — Result
type - operators/result_operators.md — ?, ?!, ?|, drop, raw, catch
- main_failsafe.md — exit instead of pass/fail