Skip to content
Discussions/App Development/Error "Missing field: commands" when running triggerForum ↗

Error "Missing field: commands" when running trigger

App Development6 posts526 views4 likesLast activity Apr 2020
GE
georgOP
Apr 2020

I wrote a trigger with the following rule:

acceptRule : Party -> ACS -> Time -> Map CommandId [Command] -> s -> TriggerA ()
acceptRule party acs t pending s = do
  let proposals = getContracts @IssueProposal acs
  let pcids = map fst proposals
  let cmds = map (\cid -> exerciseCmd cid Accept) pcids
  let pendings = map (\c -> c.contractId) cmds
  emitCommands cmds pendings
  pure ()

When I try to run it I get the following message repeated indefinitely:

Command failed: Missing field: commands, code: 3

What am I doing wrong here?

CO
cocreature
Apr 2020

I’m somewhat guessing here but I believe that cmds is probably empty. The ledger API does not accept empty list of commands. If that is the issue you can simply wrap it in when:

when (not (null cmds)) (emitCommands cmds pendings)

Might make sense to modify emitCommands to handle this automatically.

GE
georg
Apr 2020

Thanks. When I try your suggestion I get a type mismatch:

Couldn't match type ‘CommandId’ with ‘()’
      Expected type: TriggerA ()
        Actual type: TriggerA CommandId

I changed it to:

  when (L.null cmds) do
    emitCommands cmds pendings
    pure ()

Is there a one-liner to do the same?

CO
cocreature
Apr 2020

Ah good point, you can use the void function to turn this into a one-liner:

when (not $ null cmds) $ void $ emitCommands cmds pendings

Note the not. You seem to have lost that when you changed it.

GE
georg
Apr 2020

Ah, thanks. Yep, missed the not but I’ve now ended up using unless anyway.

CO
cocreature
Apr 2020

Good point, unless makes more sense here.

← Back to Discussions