---
title: "U3009: Failure variant not in the declared error kind"
url: https://una-lang.org/en/docs/errors/U3009/
release: v0.4.0
source: https://github.com/una-lang/una/blob/v0.4.0/crates/una-explain/explain/U3009.md
---

# U3009: Failure variant not in the declared error kind

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:

- `fail` after `if error` and `if none`;
- `checked`;
- handler operations, which fail only with their operation's error kind (`spec/05 §5`);
- a function passed as an argument, which fails only as its expected function type allows (`spec/10 §2`).

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
```
