I am trying to create a Daml Script that creates Users and Parties on the ledger.
createUsersAndParties = script do
let
userParties = [
("alice", "Alice"),
("bob", "Bob")]
forA_ userParties $ uncurry allocatePartyAndCreateUser
users <- listAllUsers
return (users)
allocatePartyAndCreateUser userId partyId = script do
allocatePartyWithHint partyId (PartyIdHint partyId)
userIdValidated <- validateUserId userId
createUser (User userIdValidated (Some party)) [CanActAs party]
return()
This script could potentially be run more than once, so I would like the script on the second run to just list all the users. When I change the code to the following:
createUsersAndParties = script do
let
userParties = [
("alice", "Alice"),
("bob", "Bob")]
forA_ userParties $ uncurry allocatePartyAndCreateUser
forA_ userParties $ uncurry allocatePartyAndCreateUser
users <- listAllUsers
return (users)
I get the error:
Script execution failed:
Tried to allocate a party that already exists: Alice
Is there a way to add a try catch in the allocatePartyAndCreateUser function? I have tried using GeneralError as the catch argument but that did not work?