Troubleshooting in DAML Models

Reading Time: 3 minutes

Sometimes while creating our DAML Models we often do some mistakes, which interrupt our basic flow. Inspite of good DAML Design which we discussed in our previous blog, we may make some mistakes while creating Templates. Before moving further we assume that you know how to write Templates in DAML if not then please go through with this blog.

Some of the errors we face while creating our DAML Models  are:

Error: “<X> is not authorized to commit an update

This error occurs when there are multiple obligables  on a contract. In DAML we can’t create that will force some other party (or parties) into an obligation. This error means that a party is trying to do something that would force other parties into an agreement without their consent.

Let see it with an example

module Abc where
template Product
  signatory first_person,second_person
  controller first_person,second_person can
    ArchiveContract : ()

Now write Test scenario for this example

test1 = scenario do
first <- getParty "Kamal"
second <- getParty "Suresh"
submit first do
  create Product with
    first_person = first
    second_person = second

As mentioned earlier, in our template, we need permission from both parties to create a Product contract. So, if any individual party try to create a contract then an authorization error will be shown as below.

Solution to this problem

To solve this, make sure each party is entering into the contract freely by exercising a choice. A good way of ensuring this is the “initial and accept” pattern.

Error “Argument is not of serializable type”

This error occurs when you are using a function as a parameter to a template. For example, here is a contract that creates a Payout controller by a receiver’s supervisor.

Let see it with an example

template SupervisedPayout
    supervisor : Party -> Party
    receiver   : Party
    giver      : Party
    amount     : Decimal
    controller (supervisor receiver) can
        returning ContractId Payout
        to create Payout with giver; receiver; amount

Hovering over the compilation error displays:

[Type checker] Argument expands to non-serializable type Party -> Party.

For more detail over serializable issue visit here

Error “Variable not in scope”

Sometimes while writing test scenarios we need to provide expected parameters to template or choice. So we assign them explicitly with their actual name and if we forget to mention it then we will get a Not in scope error.

Let see it with an example

module Abc where
data Tdata = Tdata
   age :Int
template HaskTest
   tdata :Tdata
   signatory tdata.owner

Now write Test Scenario

test = scenario do
 p <- getParty "Alice"
   tdatav = Tdata with
     owner = p
     comment ="test"
     age =3
 submit tdatav.owner do create HaskTest with tdatav

We are trying to pass tdatav to HaskTest without explicitly assigning to tdata so we get following error in our model.

Solution to this Problem

So to overcome this problem we have to explicitly assign tdatav to tdata. Try to provide proper assignment while passing arguments.

Error “Cyclic module dependency”

We saw this type of error when we are importing  Modules in Cyclic form. It lies between two or more modules which either directly or indirectly depend on each other to function properly.

Let see it with an example Suppose you have two different modules ABC and BCD in two different files.

Module ABC

module Abc where
import BCD
template A
  owner :Party
   signatory owner
   controller owner can
    CreateB: ContractId B
        create B with newOwner=owner
template C
  lastOwner :Party
   signatory lastOwner

Module BCD

module BCD where
import Abc
template B
  newOwner :Party
   signatory newOwner
   controller newOwner can
    CreateB: ContractId C
        create C with lastOwner = newowner

As we can see Module ABC is importing Module BCD to create Contract B similarly Module BCD is importing Module ABC to create Contract C so we get a Cyclic Module Dependency error as shown below.

Solution to this Problem

Try to aggregate all Dependent DAML Module in individual file.

References :