Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/Catching failed key lookupForum ↗

Catching failed key lookup

App Development2 posts206 views1 likesLast activity Feb 2022
LU
LucianoOP
Feb 2022

If I run this code, which creates a t if it doesn’t exist already:

lookupOrCreate : (HasCreate t, HasFetchByKey t t)  => t  -> Update t
lookupOrCreate = 
  try fst <$> fetchByKey t
  catch _ -> create t

The catch will not trigger, and I get an error

Attempt 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?

CO
cocreature
Feb 2022

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.

← Back to Discussions