Skip to content

Commit

Permalink
Remove QueryCmdLocalStateQueryError: its only use is better served by…
Browse files Browse the repository at this point in the history
… QueryCmdEraMismatch
  • Loading branch information
smelc committed Dec 13, 2024
1 parent d37c5f7 commit c730206
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 49 deletions.
1 change: 0 additions & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -1874,4 +1874,4 @@ easyRunQuery
easyRunQuery q =
lift q
& onLeft (left . QueryCmdUnsupportedNtcVersion)
& onLeft (left . QueryCmdLocalStateQueryError . EraMismatchError)
& onLeft (left . QueryCmdEraMismatch)
17 changes: 12 additions & 5 deletions cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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 ->
Expand Down

This file was deleted.

0 comments on commit c730206

Please sign in to comment.