---
title: "U3029: A failure that must be handled where it is not"
url: https://una-lang.org/en/docs/errors/U3029/
release: v0.4.0
source: https://github.com/una-lang/una/blob/v0.4.0/crates/una-explain/explain/U3029.md
---

# U3029: A failure that must be handled where it is not

A failure is not handled inside code that runs where no caller can receive it.

## Why Una rejects it

Some code runs where no caller can receive a failure, so each failure it meets is handled inside it, with `if error use` or `attempt` (`spec/26`, ADR 0116):
- an `on stop` block, which runs once its loop has ended, after a failure of the body too, so that a failure of its own would hide the first (rule 10);
- `step` and `on_stop` of a driven module, which declare no `fails`, since the host has no caller to give a failure to (rule 2);
- `on_stop` of the module of a `serve` section, which declares no `fails` for the same reason (`spec/31 §7`, ADR 0123 rule 16); its `handle` may, and the host answers a failed request with `500`;
- the expression of a `start`, whose task no code waits on for a value or a failure (`spec/27 §7`, ADR 0117 rule 7).

The error is at the statement, or at the `fails` clause.

## The repair at a glance

`src/demo.una`

```diff
  module demo

  pub kind Lost = | Gone

  close(name: Text) -> Unit
    fails Lost
  =
    if name == "" then fail Gone else unit

  pub run() -> Unit
-   fails Lost
    diverges
  =
    for ever
      stop
    on stop
      close("log")
+       if error use unit
    unit
```

## Failing example

`ita.una`

```una
ita demo
  version 0.1.0
  edition 0.4
```

`ita.lock`

```una
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
```

`src/demo.una`

```una
module demo

pub kind Lost = | Gone

close(name: Text) -> Unit
  fails Lost
=
  if name == "" then fail Gone else unit

pub run() -> Unit
  fails Lost
  diverges
=
  for ever
    stop
  on stop
    close("log")
  unit
```

## Fixed example

`ita.una`

```una
ita demo
  version 0.1.0
  edition 0.4
```

`ita.lock`

```una
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
```

`src/demo.una`

```una
module demo

pub kind Lost = | Gone

close(name: Text) -> Unit
  fails Lost
=
  if name == "" then fail Gone else unit

pub run() -> Unit
  diverges
=
  for ever
    stop
  on stop
    close("log")
      if error use unit
  unit
```
