Catching failed key lookup
- LucianoOP
If I run this code, which creates a
tif it doesn’t exist already:lookupOrCreate : (HasCreate t, HasFetchByKey t t) => t -> Update t lookupOrCreate = try fst <$> fetchByKey t catch _ -> create tThe
catchwill not trigger, and I get an errorAttempt to fetch or exercise by key but no contract with that key was found.I suppose I can work around this by using
lookupByKey, but I’m curious to understand why this exception is not captured? - cocreature 1
If you allow catching this, you turn a fetchByKey into a lookupByKey. However, lookupByKey and fetchByKey have different authorization and visibility rules, see Contract keys — Daml SDK 1.18.1 documentation so that doesn’t really work.