From c730206d2a3fd27e0624d9c249983bebb5289d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Fri, 13 Dec 2024 09:56:46 +0100 Subject: [PATCH] Remove QueryCmdLocalStateQueryError: its only use is better served by QueryCmdEraMismatch --- cardano-cli/cardano-cli.cabal | 1 - .../src/Cardano/CLI/EraBased/Run/Query.hs | 16 ++++----- .../Cardano/CLI/Types/Errors/QueryCmdError.hs | 17 ++++++--- .../Errors/QueryCmdLocalStateQueryError.hs | 35 ------------------- 4 files changed, 20 insertions(+), 49 deletions(-) delete mode 100644 cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdLocalStateQueryError.hs diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index f576f41feb..79406db539 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -176,7 +176,6 @@ library Cardano.CLI.Types.Errors.PlutusScriptDecodeError Cardano.CLI.Types.Errors.ProtocolParamsError Cardano.CLI.Types.Errors.QueryCmdError - Cardano.CLI.Types.Errors.QueryCmdLocalStateQueryError Cardano.CLI.Types.Errors.RegistrationError Cardano.CLI.Types.Errors.ScriptDataError Cardano.CLI.Types.Errors.ScriptDecodeError diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs index e2bfd5a6c2..818719c46f 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs @@ -52,7 +52,6 @@ import Cardano.CLI.Helpers import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.NodeEraMismatchError import Cardano.CLI.Types.Errors.QueryCmdError -import Cardano.CLI.Types.Errors.QueryCmdLocalStateQueryError import Cardano.CLI.Types.Key import Cardano.CLI.Types.Output (QueryDRepStateOutput (..)) import qualified Cardano.CLI.Types.Output as O @@ -1840,9 +1839,7 @@ requireEon -- TODO: implement 'Bounded' for `Some eon` and remove 'minEra' requireEon minEra era = hoistMaybe - ( QueryCmdLocalStateQueryError $ - mkEraMismatchError NodeEraMismatchError{nodeEra = era, era = minEra} - ) + (mkEraMismatchError NodeEraMismatchError{nodeEra = era, era = minEra}) (forEraMaybeEon era) -- | The output format to use, for commands with a recently introduced --output-[json,text] flag @@ -1858,13 +1855,16 @@ newOutputFormat format mOutFile = strictTextToLazyBytestring :: Text -> LBS.ByteString strictTextToLazyBytestring t = BS.fromChunks [Text.encodeUtf8 t] -easyRunQueryCurrentEra :: ExceptT QueryCmdError (LocalStateQueryExpr block point QueryInMode r IO) AnyCardanoEra +easyRunQueryCurrentEra + :: ExceptT QueryCmdError (LocalStateQueryExpr block point QueryInMode r IO) AnyCardanoEra easyRunQueryCurrentEra = lift queryCurrentEra & onLeft (left . QueryCmdUnsupportedNtcVersion) -easyRunQueryEraHistory :: ExceptT QueryCmdError (LocalStateQueryExpr block point QueryInMode r IO) EraHistory +easyRunQueryEraHistory + :: ExceptT QueryCmdError (LocalStateQueryExpr block point QueryInMode r IO) EraHistory easyRunQueryEraHistory = lift queryEraHistory & onLeft (left . QueryCmdUnsupportedNtcVersion) -easyRunQuerySystemStart :: ExceptT QueryCmdError (LocalStateQueryExpr block point QueryInMode r IO) SystemStart +easyRunQuerySystemStart + :: ExceptT QueryCmdError (LocalStateQueryExpr block point QueryInMode r IO) SystemStart easyRunQuerySystemStart = lift querySystemStart & onLeft (left . QueryCmdUnsupportedNtcVersion) easyRunQuery @@ -1874,4 +1874,4 @@ easyRunQuery easyRunQuery q = lift q & onLeft (left . QueryCmdUnsupportedNtcVersion) - & onLeft (left . QueryCmdLocalStateQueryError . EraMismatchError) \ No newline at end of file + & onLeft (left . QueryCmdEraMismatch) diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdError.hs index c271d53858..1589963411 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdError.hs @@ -5,12 +5,14 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} module Cardano.CLI.Types.Errors.QueryCmdError ( QueryCmdError (..) , renderQueryCmdError + , mkEraMismatchError ) where @@ -21,7 +23,7 @@ import Cardano.Api.Shelley hiding (QueryInShelleyBasedEra (..)) import Cardano.Binary (DecoderError) import Cardano.CLI.Helpers (HelpersError (..), renderHelpersError) import Cardano.CLI.Types.Errors.GenesisCmdError -import Cardano.CLI.Types.Errors.QueryCmdLocalStateQueryError +import Cardano.CLI.Types.Errors.NodeEraMismatchError (NodeEraMismatchError (..)) import qualified Data.ByteString.Lazy.Char8 as LBS import Data.Text.Lazy.Builder (toLazyText) @@ -31,8 +33,7 @@ import Formatting.Buildable (build) {- HLINT ignore "Redundant flip" -} data QueryCmdError - = QueryCmdLocalStateQueryError !QueryCmdLocalStateQueryError - | QueryCmdConvenienceError !QueryConvenienceError + = QueryCmdConvenienceError !QueryConvenienceError | QueryCmdWriteFileError !(FileError ()) | QueryCmdHelpersError !HelpersError | QueryCmdAcquireFailure !AcquiringFailure @@ -56,10 +57,16 @@ data QueryCmdError | QueryCmdCommitteeHotKeyError !(FileError InputDecodeError) deriving Show +mkEraMismatchError :: NodeEraMismatchError -> QueryCmdError +mkEraMismatchError NodeEraMismatchError{nodeEra, era} = + QueryCmdEraMismatch $ + EraMismatch + { ledgerEraName = docToText $ pretty nodeEra + , otherEraName = docToText $ pretty era + } + renderQueryCmdError :: QueryCmdError -> Doc ann renderQueryCmdError = \case - QueryCmdLocalStateQueryError 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 deleted file mode 100644 index f9f7005773..0000000000 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdLocalStateQueryError.hs +++ /dev/null @@ -1,35 +0,0 @@ -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE NamedFieldPuns #-} - -module Cardano.CLI.Types.Errors.QueryCmdLocalStateQueryError - ( QueryCmdLocalStateQueryError (..) - , mkEraMismatchError - ) -where - -import Cardano.Api -import Cardano.Api.Consensus (EraMismatch (..)) - -import Cardano.CLI.Types.Errors.NodeEraMismatchError - --- | An error that can occur while querying a node's local state. -newtype QueryCmdLocalStateQueryError - = -- | A query from a certain era was applied to a ledger from a different era. - EraMismatchError EraMismatch - deriving (Eq, Show) - -mkEraMismatchError :: NodeEraMismatchError -> QueryCmdLocalStateQueryError -mkEraMismatchError NodeEraMismatchError{nodeEra, era} = - EraMismatchError - EraMismatch - { ledgerEraName = docToText $ pretty nodeEra - , otherEraName = docToText $ pretty era - } - -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