Skip to content

Commit

Permalink
Fix era mismatch error in stake-address-info
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Nov 29, 2023
1 parent d00a7d4 commit 5d247f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
10 changes: 4 additions & 6 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ module Cardano.CLI.EraBased.Run.Query

, DelegationsAndRewards(..)
, renderQueryCmdError
, renderLocalStateQueryError
, renderOpCertIntervalInformation
, percentage
) where
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ data QueryCmdError
renderQueryCmdError :: QueryCmdError -> Doc ann
renderQueryCmdError = \case
QueryCmdLocalStateQueryError lsqErr ->
renderLocalStateQueryError lsqErr
prettyError lsqErr
QueryCmdWriteFileError fileErr ->
prettyError fileErr
QueryCmdHelpersError helpersErr ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@
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
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

0 comments on commit 5d247f9

Please sign in to comment.