Skip to content

Commit

Permalink
Merge pull request #527 from abailly-iohk/witness-error-message
Browse files Browse the repository at this point in the history
Provide more detailed error upon missing policy id
  • Loading branch information
carbolymer authored Feb 5, 2024
2 parents 3b70e39 + 823d81a commit 083a25c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ createTxMintValue era (val, scriptWitnesses) =

validateAllWitnessesProvided witnessesNeeded witnessesProvided
| null witnessesMissing = return ()
| otherwise = Left (TxCmdPolicyIdsMissing witnessesMissing)
| otherwise = Left (TxCmdPolicyIdsMissing witnessesMissing (toList witnessesProvided))
where
witnessesMissing = Set.elems (witnessesNeeded Set.\\ witnessesProvided)

Expand Down
19 changes: 13 additions & 6 deletions cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ data TxCmdError
| TxCmdTxBodyError !TxBodyError
| TxCmdNotImplemented !Text
| TxCmdWitnessEraMismatch !AnyCardanoEra !AnyCardanoEra !WitnessFile
| TxCmdPolicyIdsMissing ![PolicyId]
| TxCmdPolicyIdsMissing ![PolicyId] ![PolicyId]
-- The first list is the missing policy Ids, the second list is the
-- policy Ids that were provided in the transaction.
| TxCmdPolicyIdsExcess ![PolicyId]
| TxCmdByronEra
| TxCmdBalanceTxBody !TxBodyErrorAutoBalance
Expand Down Expand Up @@ -130,19 +132,20 @@ renderTxCmdError = \case
"The transaction is for the " <> pretty era <> " era, but the " <>
"witness in " <> pshow file <> " is for the " <> pretty era' <> " era."

TxCmdPolicyIdsMissing policyids ->
mconcat
TxCmdPolicyIdsMissing missingPolicyIds knownPolicyIds ->
mconcat $
[ "The \"--mint\" flag specifies an asset with a policy Id, but no "
, "corresponding monetary policy script has been provided as a witness "
, "(via the \"--mint-script-file\" flag). The policy Id in question is: "
, mconcat $ List.intersperse ", " (map (pretty . serialiseToRawBytesHexText) policyids)
]
, prettyPolicyIdList missingPolicyIds
] <> [". Known policy Ids are: " <> prettyPolicyIdList knownPolicyIds | not (null knownPolicyIds) ]


TxCmdPolicyIdsExcess policyids ->
mconcat
[ "A script provided to witness minting does not correspond to the policy "
, "id of any asset specified in the \"--mint\" field. The script hash is: "
, mconcat $ List.intersperse ", " (map (pretty . serialiseToRawBytesHexText) policyids)
, prettyPolicyIdList policyids
]
TxCmdByronEra ->
"This query cannot be used for the Byron era"
Expand Down Expand Up @@ -220,3 +223,7 @@ renderTxCmdError = \case
prettyError e
TxCmdScriptValidityValidationError e ->
prettyError e

prettyPolicyIdList :: [PolicyId] -> Doc ann
prettyPolicyIdList =
mconcat . List.intersperse ", " . fmap (pretty . serialiseToRawBytesHexText)

0 comments on commit 083a25c

Please sign in to comment.