fail returns an error to the caller, so the function's return type must say it can fail:
T! or T!E. Visible failure is a core Auk rule: a caller can tell from the signature alone.
Wrong#
fn check(n: int): int {
if n < 0 { fail("negative") }
n
}Fixed#
fn check(n: int): int! {
if n < 0 { fail("negative") }
n
}Common causes#
- A function that can fail but whose return type doesn't end in
!. failinside a closure: closures don't carry the enclosing function's error type.- To stop the program on a bug, use
assertor!instead.