From 5748462a89b9a2c409a9ca9b15e02c6d9eb5289e Mon Sep 17 00:00:00 2001 From: John Ky Date: Tue, 14 Feb 2023 22:57:36 +1100 Subject: [PATCH] Error when costmodel is empty in create-update-proposal --- .../src/Cardano/CLI/Shelley/Run/Governance.hs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Governance.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Governance.hs index d25e2ee903b..4d54e3e734d 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Governance.hs @@ -10,6 +10,8 @@ import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT onLeft) import Data.Aeson (eitherDecode) import qualified Data.ByteString.Lazy as LB +import Data.Function ((&)) +import qualified Data.List as List import Data.Text (Text) import qualified Data.Text as Text @@ -21,9 +23,8 @@ import Cardano.CLI.Shelley.Key (VerificationKeyOrHashOrFile, import Cardano.CLI.Shelley.Parsers import Cardano.CLI.Types +import Cardano.Ledger.Alonzo.Scripts (CostModels (..)) import qualified Cardano.Ledger.Shelley.TxBody as Shelley -import Control.Monad.IO.Unlift (MonadIO (..)) -import Data.Function ((&)) data ShelleyGovernanceCmdError @@ -39,6 +40,7 @@ data ShelleyGovernanceCmdError !Int -- ^ Number of reward amounts | ShelleyGovernanceCmdCostModelsJsonDecodeErr !FilePath !Text + | ShelleyGovernanceCmdEmptyCostModel !FilePath deriving Show renderShelleyGovernanceError :: ShelleyGovernanceCmdError -> Text @@ -55,8 +57,10 @@ renderShelleyGovernanceError err = <> " The number of staking keys: " <> textShow numVKeys <> " and the number of reward amounts: " <> textShow numRwdAmts <> " are not equivalent." - ShelleyGovernanceCmdCostModelsJsonDecodeErr err' fp -> - "Error decoding cost model: " <> Text.pack err' <> " at: " <> fp + ShelleyGovernanceCmdCostModelsJsonDecodeErr fp err' -> + "Error decoding cost model: " <> err' <> " at: " <> Text.pack fp + ShelleyGovernanceCmdEmptyCostModel fp -> + "The decoded cost model was empty at: " <> Text.pack fp ShelleyGovernanceCmdCostModelReadError err' -> "Error reading the cost model: " <> Text.pack (displayError err') @@ -163,6 +167,8 @@ runGovernanceUpdateProposal (OutputFile upFile) eNo genVerKeyFiles upPprams mCos cModels <- pure (eitherDecode costModelsBs) & onLeft (left . ShelleyGovernanceCmdCostModelsJsonDecodeErr fp . Text.pack) + when (List.null (unCostModels cModels)) $ left (ShelleyGovernanceCmdEmptyCostModel fp) + return $ upPprams {protocolUpdateCostModels = fromAlonzoCostModels cModels} when (finalUpPprams == mempty) $ left ShelleyGovernanceCmdEmptyUpdateProposalError