From 5d247f9643cf9144a567c12397ef2996f4de815e Mon Sep 17 00:00:00 2001 From: Mateusz Galazyn Date: Wed, 29 Nov 2023 15:51:19 +0100 Subject: [PATCH] Fix era mismatch error in stake-address-info --- cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs | 10 ++++------ .../src/Cardano/CLI/Types/Errors/QueryCmdError.hs | 2 +- .../Types/Errors/QueryCmdLocalStateQueryError.hs | 15 ++++++++------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs index 9e2ec0646b..39da1f183a 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs @@ -32,7 +32,6 @@ module Cardano.CLI.EraBased.Run.Query , DelegationsAndRewards(..) , renderQueryCmdError - , renderLocalStateQueryError , renderOpCertIntervalInformation , percentage ) where @@ -821,11 +820,10 @@ runQueryStakeAddressInfoCmd & onLeft (left . QueryCmdUnsupportedNtcVersion) & onLeft (left . QueryCmdLocalStateQueryError . EraMismatchError) - ceo <- requireEon ConwayEra era - - stakeVoteDelegatees <- lift (queryStakeVoteDelegatees ceo stakeAddr) - & onLeft (left . QueryCmdUnsupportedNtcVersion) - & onLeft (left . QueryCmdLocalStateQueryError . EraMismatchError) + stakeVoteDelegatees <- monoidForEraInEonA era $ \ceo -> + lift (queryStakeVoteDelegatees ceo stakeAddr) + & onLeft (left . QueryCmdUnsupportedNtcVersion) + & onLeft (left . QueryCmdLocalStateQueryError . EraMismatchError) return $ do writeStakeAddressInfo diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdError.hs index a46e3353c7..116d96d5ca 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdError.hs @@ -59,7 +59,7 @@ data QueryCmdError renderQueryCmdError :: QueryCmdError -> Doc ann renderQueryCmdError = \case QueryCmdLocalStateQueryError lsqErr -> - renderLocalStateQueryError lsqErr + prettyError lsqErr QueryCmdWriteFileError fileErr -> prettyError fileErr QueryCmdHelpersError helpersErr -> diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdLocalStateQueryError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdLocalStateQueryError.hs index 5df2ebb9bf..44afcee177 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdLocalStateQueryError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdLocalStateQueryError.hs @@ -4,19 +4,20 @@ module Cardano.CLI.Types.Errors.QueryCmdLocalStateQueryError ( QueryCmdLocalStateQueryError(..) , mkEraMismatchError - , renderLocalStateQueryError ) where +import Cardano.Api (Error (..)) import Cardano.Api.Pretty import Cardano.CLI.Types.Errors.NodeEraMismatchError import Ouroboros.Consensus.Cardano.Block (EraMismatch (..)) +import Prettyprinter ((<+>)) + -- | An error that can occur while querying a node's local state. newtype QueryCmdLocalStateQueryError = EraMismatchError EraMismatch - -- ^ A query from a certain era was applied to a ledger from a different - -- era. + -- ^ A query from a certain era was applied to a ledger from a different era. deriving (Eq, Show) mkEraMismatchError :: NodeEraMismatchError -> QueryCmdLocalStateQueryError @@ -24,7 +25,7 @@ mkEraMismatchError NodeEraMismatchError{nodeEra, era} = EraMismatchError EraMismatch{ ledgerEraName = docToText $ pretty nodeEra , otherEraName = docToText $ pretty era} -renderLocalStateQueryError :: QueryCmdLocalStateQueryError -> Doc ann -renderLocalStateQueryError = \case - EraMismatchError err -> - "A query from a certain era was applied to a ledger from a different era: " <> pshow err +instance Error QueryCmdLocalStateQueryError where + prettyError = \case + EraMismatchError EraMismatch{ledgerEraName, otherEraName} -> + "A query from" <+> pretty otherEraName <+> "era was applied to a ledger from a different era:" <+> pretty ledgerEraName