Home / Docs / Diagnostics

U3009: Failure variant not in the declared error kind

Release v0.4.0

A failure names a variant that is not a variant of the function's error kind.

Why Una rejects it

fail V ends the function with a failure, and V must be a variant of the function's error kind (spec/06 §2). A function without fails cannot fail (spec/04 §2 rule 4).

The same holds for:

A private function without fails has the error kind of its first failure in source order inferred, a raised variant or a passed failure (spec/04 §5 rule 3, ADR 0099), so a variant of another kind is reported where it is raised.

The repair at a glance

diff
  module demo

  kind StoreError = Timeout | Corrupted

  kind LookupError = Missing | Unavailable

  pub check(key: Int) -> Int
    fails LookupError
  =
-   if key < 0 then fail Timeout else key
+   if key < 0 then fail Missing else key

Failing example

una
module demo

kind StoreError = Timeout | Corrupted

kind LookupError = Missing | Unavailable

pub check(key: Int) -> Int
  fails LookupError
=
  if key < 0 then fail Timeout else key

Fixed example

una
module demo

kind StoreError = Timeout | Corrupted

kind LookupError = Missing | Unavailable

pub check(key: Int) -> Int
  fails LookupError
=
  if key < 0 then fail Missing else key