Skip to content

Commit

Permalink
Provide more detailed error upon missing policy id
Browse files Browse the repository at this point in the history
When one gets this error while still providing one or more
--mint-script-file, it can be confusing. This commit adds the list of
"known" policy ids to the error message in order to help user
troubleshoot their issue which might be related to an incorrectly
computed hash or a wrong script.
  • Loading branch information
abailly committed Dec 20, 2023
1 parent 06e27c9 commit 61880a9
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 @@ -875,7 +875,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,7 @@ data TxCmdError
| TxCmdTxBodyError !TxBodyError
| TxCmdNotImplemented !Text
| TxCmdWitnessEraMismatch !AnyCardanoEra !AnyCardanoEra !WitnessFile
| TxCmdPolicyIdsMissing ![PolicyId]
| TxCmdPolicyIdsMissing ![PolicyId] ![PolicyId]
| TxCmdPolicyIdsExcess ![PolicyId]
| TxCmdByronEra
| TxCmdBalanceTxBody !TxBodyErrorAutoBalance
Expand Down Expand Up @@ -130,19 +130,22 @@ 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
] <> if (null knownPolicyIds)

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs:139:13-33: Suggestion: Redundant bracket
  
Found:
  if (null knownPolicyIds) then
      []
  else
      [". Known policy Ids are: " <> prettyPolicyIdList knownPolicyIds]
  
Perhaps:
  if null knownPolicyIds then
      []
  else
      [". Known policy Ids are: " <> prettyPolicyIdList knownPolicyIds]
then []
else [". Known policy Ids are: " <> prettyPolicyIdList knownPolicyIds ]

Check notice

Code scanning / HLint

Use list comprehension Note

cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs:(139,10)-(141,80): Suggestion: Use list comprehension
  
Found:
  if (null knownPolicyIds) then
      []
  else
      [". Known policy Ids are: " <> prettyPolicyIdList knownPolicyIds]
  
Perhaps:
  ([". 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 61880a9

Please sign in to comment.