Home / Docs / Diagnostics
U3029: A failure that must be handled where it is not
Release v0.4.0
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 stopblock, 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); stepandon_stopof a driven module, which declare nofails, since the host has no caller to give a failure to (rule 2);on_stopof the module of aservesection, which declares nofailsfor the same reason (spec/31 §7, ADR 0123 rule 16); itshandlemay, and the host answers a failed request with500;- 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
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
unitFailing example
ita.una
ita demo
version 0.1.0
edition 0.4ita.lock
lock 1
solver
encoding "una-smt-1"
name "z3"
version "5.1.0"
logic "QF_UFLIA"
steps 5000000
seed 0src/demo.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")
unitFixed example
ita.una
ita demo
version 0.1.0
edition 0.4ita.lock
lock 1
solver
encoding "una-smt-1"
name "z3"
version "5.1.0"
logic "QF_UFLIA"
steps 5000000
seed 0src/demo.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