Home / Docs / Diagnostics

U3026: attempt of a call that cannot fail

Release v0.4.0

The operand of an attempt is a call that cannot fail.

Why Una rejects it

In edition 0.3, the operand of attempt must be a call that can fail (spec/06 §5, ADR 0100). attempt of a call that cannot fail gives a Result whose Err arm is never taken, with an error type that the program never produces.

The rule waits while the package has an error that can hide a failure, as U3025 does.

Editions 0.1 and 0.2 accept the attempt.

How to fix it

Remove attempt and use the value of the call directly. Then unwrap each use of the Result:

The repair describes this change and carries no edit, since the uses must change with it.

The repair at a glance

src/demo.unadiff
  module demo

  double(n: Int) -> Int = n * 2

- pub tried(n: Int) -> Result[Int, Text] = attempt double(n)
+ pub tried(n: Int) -> Int = double(n)

Failing example

una.tomltoml
[package]
name = "demo"
version = "0.1.0"
edition = "0.3"
src/demo.unauna
module demo

double(n: Int) -> Int = n * 2

pub tried(n: Int) -> Result[Int, Text] = attempt double(n)

Fixed example

una.tomltoml
[package]
name = "demo"
version = "0.1.0"
edition = "0.3"
src/demo.unauna
module demo

double(n: Int) -> Int = n * 2

pub tried(n: Int) -> Int = double(n)