Home / Docs / Diagnostics
U3007: Fallible expression without handling
Release v0.4.0
Failures never propagate implicitly: a statement, let or final expression that can fail is followed by an if error clause, or its call is wrapped in attempt (spec/06 §3, §5). if error fail V turns the failure into a variant of the function's error kind, if error pass propagates it unchanged when the kinds are equal, and if error use e recovers with a value. The message names the call and the error kind it can fail with.
The repair at a glance
diff
module demo
kind StoreError = Timeout | Corrupted
capability Store
op find(key: Int) -> Option[Int]
fails StoreError
pub has(key: Int) -> Bool
uses @store: Store[find]
=
let found = @store.find(key)
+ if error use None
found.is_some()Failing example
una
module demo
kind StoreError = Timeout | Corrupted
capability Store
op find(key: Int) -> Option[Int]
fails StoreError
pub has(key: Int) -> Bool
uses @store: Store[find]
=
let found = @store.find(key)
found.is_some()Fixed example
una
module demo
kind StoreError = Timeout | Corrupted
capability Store
op find(key: Int) -> Option[Int]
fails StoreError
pub has(key: Int) -> Bool
uses @store: Store[find]
=
let found = @store.find(key)
if error use None
found.is_some()