From 61880a94d94179aa2ae1f469679518819926327b Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Wed, 20 Dec 2023 11:34:49 +0100 Subject: [PATCH] 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)