In the following code…
import Daml.Script
import DA.Text
template Asset with
party : Party
description : Text
where
signatory party
ensure
not $ isEmpty description
description_is_required = script do
party <- allocateParty "party"
submit party $ createCmd Asset with description = "", ..
…the error message is Template precondition violated: Asset {party = 'party', description = ""}
, which may not be helpful, especially for really large templates. I’d like to provide a more helpful error message.
Is there a better way than the following ensure
block?
ensure
let isNotEmpty val name = (not (isEmpty val) || error ("The field " <> name <> " cannot be empty.")) in
isNotEmpty description "description"
By “better way” I mean, am I overlooking existing functionality that does this already? Is error
the right function? Or should I try to use abort
? etc.