From 61880a94d94179aa2ae1f469679518819926327b Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Wed, 20 Dec 2023 11:34:49 +0100 Subject: [PATCH 1/2] Provide more detailed error upon missing policy id 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. --- .../Cardano/CLI/EraBased/Run/Transaction.hs | 2 +- .../Cardano/CLI/Types/Errors/TxCmdError.hs | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index b806a5d561..47109bbde6 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -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) diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs index 35fee53f87..96ff212a33 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs @@ -48,7 +48,7 @@ data TxCmdError | TxCmdTxBodyError !TxBodyError | TxCmdNotImplemented !Text | TxCmdWitnessEraMismatch !AnyCardanoEra !AnyCardanoEra !WitnessFile - | TxCmdPolicyIdsMissing ![PolicyId] + | TxCmdPolicyIdsMissing ![PolicyId] ![PolicyId] | TxCmdPolicyIdsExcess ![PolicyId] | TxCmdByronEra | TxCmdBalanceTxBody !TxBodyErrorAutoBalance @@ -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) + then [] + else [". Known policy Ids are: " <> prettyPolicyIdList 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" @@ -220,3 +223,7 @@ renderTxCmdError = \case prettyError e TxCmdScriptValidityValidationError e -> prettyError e + +prettyPolicyIdList :: [PolicyId] -> Doc ann +prettyPolicyIdList = + mconcat . List.intersperse ", " . fmap (pretty . serialiseToRawBytesHexText) From 823d81a4cb4557c2ff87fcf55589ac53d30d934c Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Wed, 20 Dec 2023 22:13:49 +0100 Subject: [PATCH 2/2] Fix from PR review and hlint --- cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs index 96ff212a33..70493025b2 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs @@ -49,6 +49,8 @@ data TxCmdError | TxCmdNotImplemented !Text | TxCmdWitnessEraMismatch !AnyCardanoEra !AnyCardanoEra !WitnessFile | 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 @@ -136,9 +138,7 @@ renderTxCmdError = \case , "corresponding monetary policy script has been provided as a witness " , "(via the \"--mint-script-file\" flag). The policy Id in question is: " , prettyPolicyIdList missingPolicyIds - ] <> if (null knownPolicyIds) - then [] - else [". Known policy Ids are: " <> prettyPolicyIdList knownPolicyIds ] + ] <> [". Known policy Ids are: " <> prettyPolicyIdList knownPolicyIds | not (null knownPolicyIds) ] TxCmdPolicyIdsExcess policyids ->