Error codes

E0242: fail outside a function returning T!

In a terminal: auk explain E0242 prints this page.

On this page

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#

auk
fn check(n: int): int {
  if n < 0 { fail("negative") }
  n
}

Fixed#

auk
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 !.
  • fail inside a closure: closures don't carry the enclosing function's error type.
  • To stop the program on a bug, use assert or ! instead.

Stuck on a word? Try the glossary. Got a compiler error? Look up its code. Improve this page