Home / Docs / Diagnostics
U3012: Host capability in main not granted by una run
Release v0.4.0
A uses clause of main names a host operation that no grant allows.
Why Una rejects it
Host capabilities enter a program only through the uses of main, and una run grants only the capabilities listed in --grant flags or in the package's grants: [run] grants in una.toml, or from edition 0.4 the grants line of the run section of ita.una (spec/04 §8, spec/05 §7).
- When the package lists grants,
una checkcompares them with the host operations in theusesofmainin the entry module, and reports eachusesclause with an operation that no grant allows. una runreports it too, before anything runs, with the package's grants and those of its--grantflags together (spec/13 §5).
How to fix it
- Remove the
usesclause whenmaindoes not need the operation. - Otherwise add a grant spec for the capability, such as
"clock", to[run] grantsinuna.toml, or from edition0.4to thegrantsof therunsection ofita.una, or pass it touna runas--grant clock. The program then gets this host authority when it runs, and the repair is marked as agrantwidening (ADR 0097). - For a capability that is not a host capability, no grant provides it: install a handler for it with
withinsidemain.
The repair at a glance
una.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.1"
[run]
entry = "demo"
- grants = ["console"]
+ grants = ["console", "clock"]Failing example
una.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.1"
[run]
entry = "demo"
grants = ["console"]src/demo.una
module demo
pub main() -> Unit
uses @console: Console[print]
uses @clock: Clock[now]
=
let now = @clock.now()
@console.print("now: {now}")Fixed example
una.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.1"
[run]
entry = "demo"
grants = ["console", "clock"]src/demo.una
module demo
pub main() -> Unit
uses @console: Console[print]
uses @clock: Clock[now]
=
let now = @clock.now()
@console.print("now: {now}")