diff --git a/cardano-cli/app/cardano-cli.hs b/cardano-cli/app/cardano-cli.hs index b43ed34cce..9d5be599c3 100644 --- a/cardano-cli/app/cardano-cli.hs +++ b/cardano-cli/app/cardano-cli.hs @@ -33,4 +33,4 @@ main = toplevelExceptionHandler $ do #endif co <- Opt.customExecParser pref (opts envCli) - orDie (prettyToText . renderClientCommandError) $ runClientCommand co + orDie (docToText . renderClientCommandError) $ runClientCommand co diff --git a/cardano-cli/src/Cardano/CLI/Byron/Parsers.hs b/cardano-cli/src/Cardano/CLI/Byron/Parsers.hs index 34e92bc8d9..cc38d1402c 100644 --- a/cardano-cli/src/Cardano/CLI/Byron/Parsers.hs +++ b/cardano-cli/src/Cardano/CLI/Byron/Parsers.hs @@ -266,7 +266,7 @@ parseTxIdAtto = ( "Transaction ID (hexadecimal)") $ do bstr <- Atto.takeWhile1 Char.isHexDigit case deserialiseFromRawBytesHex AsTxId bstr of Right addr -> return addr - Left e -> fail $ prettyToString $ "Incorrect transaction id format: " <> prettyError e + Left e -> fail $ docToString $ "Incorrect transaction id format: " <> prettyError e parseTxIxAtto :: Atto.Parser TxIx parseTxIxAtto = toEnum <$> Atto.decimal diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs index 37c444ae0b..5b9068a6b0 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs @@ -178,7 +178,7 @@ parseTxId = do str' <- some Parsec.hexDigit "transaction id (hexadecimal)" case deserialiseFromRawBytesHex AsTxId (BSC.pack str') of Right addr -> return addr - Left e -> fail $ prettyToString $ "Incorrect transaction id format: " <> prettyError e + Left e -> fail $ docToString $ "Incorrect transaction id format: " <> prettyError e parseTxIx :: Parsec.Parser TxIx parseTxIx = TxIx . fromIntegral <$> decimal @@ -260,7 +260,7 @@ readVerificationKey asType = :: String -> Either String (VerificationKey keyrole) deserialiseFromBech32OrHex str' = - first (prettyToString . renderInputDecodeError) $ + first (docToString . renderInputDecodeError) $ deserialiseInput (AsVerificationKey asType) keyFormats (BSC.pack str') -- | The first argument is the optional prefix. @@ -498,14 +498,14 @@ pHexHash :: SerialiseAsRawBytes (Hash a) => AsType a -> ReadM (Hash a) pHexHash a = Opt.eitherReader $ - first (prettyToString . prettyError) + first (docToString . prettyError) . deserialiseFromRawBytesHex (AsHash a) . BSC.pack pBech32KeyHash :: SerialiseAsBech32 (Hash a) => AsType a -> ReadM (Hash a) pBech32KeyHash a = Opt.eitherReader $ - first (prettyToString . prettyError) + first (docToString . prettyError) . deserialiseFromBech32 (AsHash a) . Text.pack @@ -522,7 +522,7 @@ pGenesisDelegateVerificationKey = -> Either String (VerificationKey GenesisDelegateKey) deserialiseFromHex = first - (\e -> prettyToString $ "Invalid genesis delegate verification key: " <> prettyError e) + (\e -> docToString $ "Invalid genesis delegate verification key: " <> prettyError e) . deserialiseFromRawBytesHex (AsVerificationKey AsGenesisDelegateKey) . BSC.pack @@ -619,7 +619,7 @@ pAddCommitteeColdVerificationKeyHash = where deserialiseFromHex :: String -> Either String (Hash CommitteeColdKey) deserialiseFromHex = - first (\e -> prettyToString $ "Invalid Consitutional Committee cold key hash: " <> prettyError e) + first (\e -> docToString $ "Invalid Consitutional Committee cold key hash: " <> prettyError e) . deserialiseFromRawBytesHex (AsHash AsCommitteeColdKey) . BSC.pack @@ -640,7 +640,7 @@ pAddCommitteeColdVerificationKey = where deserialiseFromHex :: String -> Either String (VerificationKey CommitteeColdKey) deserialiseFromHex = - first (\e -> prettyToString $ "Invalid Constitutional Committee cold key: " <> prettyError e) + first (\e -> docToString $ "Invalid Constitutional Committee cold key: " <> prettyError e) . deserialiseFromRawBytesHex (AsVerificationKey AsCommitteeColdKey) . BSC.pack @@ -671,7 +671,7 @@ pRemoveCommitteeColdVerificationKeyHash = where deserialiseFromHex :: String -> Either String (Hash CommitteeColdKey) deserialiseFromHex = - first (\e -> prettyToString $ "Invalid Consitutional Committee cold key hash: " <> prettyError e) + first (\e -> docToString $ "Invalid Consitutional Committee cold key hash: " <> prettyError e) . deserialiseFromRawBytesHex (AsHash AsCommitteeColdKey) . BSC.pack @@ -692,7 +692,7 @@ pRemoveCommitteeColdVerificationKey = where deserialiseFromHex :: String -> Either String (VerificationKey CommitteeColdKey) deserialiseFromHex = - first (\e -> prettyToString $ "Invalid Constitutional Committee cold key: " <> prettyError e) + first (\e -> docToString $ "Invalid Constitutional Committee cold key: " <> prettyError e) . deserialiseFromRawBytesHex (AsVerificationKey AsCommitteeColdKey) . BSC.pack @@ -731,7 +731,7 @@ pCommitteeColdVerificationKey = where deserialiseFromHex :: String -> Either String (VerificationKey CommitteeColdKey) deserialiseFromHex = - first (\e -> prettyToString $ "Invalid Constitutional Committee cold key: " <> prettyError e) + first (\e -> docToString $ "Invalid Constitutional Committee cold key: " <> prettyError e) . deserialiseFromRawBytesHex (AsVerificationKey AsCommitteeColdKey) . BSC.pack @@ -745,7 +745,7 @@ pCommitteeColdVerificationKeyHash = where deserialiseFromHex :: String -> Either String (Hash CommitteeColdKey) deserialiseFromHex = - first (\e -> prettyToString $ "Invalid Consitutional Committee cold key hash: " <> prettyError e) + first (\e -> docToString $ "Invalid Consitutional Committee cold key hash: " <> prettyError e) . deserialiseFromRawBytesHex (AsHash AsCommitteeColdKey) . BSC.pack @@ -809,7 +809,7 @@ pCommitteeHotVerificationKey = deserialiseHotCCKeyFromHex :: String -> Either String (VerificationKey CommitteeHotKey) deserialiseHotCCKeyFromHex = - first (\e -> prettyToString $ "Invalid Constitutional Committee hot key: " <> prettyError e) + first (\e -> docToString $ "Invalid Constitutional Committee hot key: " <> prettyError e) . deserialiseFromRawBytesHex (AsVerificationKey AsCommitteeHotKey) . BSC.pack @@ -842,7 +842,7 @@ pCommitteeHotKeyHash prefix = where deserialiseFromHex :: String -> Either String (Hash CommitteeHotKey) deserialiseFromHex = - first (\e -> prettyToString $ "Invalid Consitutional Committee hot key hash: " <> prettyError e) + first (\e -> docToString $ "Invalid Consitutional Committee hot key hash: " <> prettyError e) . deserialiseFromRawBytesHex (AsHash AsCommitteeHotKey) . BSC.pack @@ -1162,7 +1162,7 @@ pScriptDataOrFile dataFlagPrefix helpTextForValue helpTextForFile = Left e -> fail $ "readerScriptData: " <> e Right sDataValue -> case scriptDataJsonToHashable ScriptDataJsonNoSchema sDataValue of - Left err -> fail $ prettyToString $ prettyError err + Left err -> fail $ docToString $ prettyError err Right sd -> return sd -------------------------------------------------------------------------------- @@ -1648,7 +1648,7 @@ pGenesisVerificationKeyHash = where deserialiseFromHex :: String -> Either String (Hash GenesisKey) deserialiseFromHex = - first (\e -> prettyToString $ "Invalid genesis verification key hash: " <> prettyError e) + first (\e -> docToString $ "Invalid genesis verification key hash: " <> prettyError e) . deserialiseFromRawBytesHex (AsHash AsGenesisKey) . BSC.pack @@ -1662,7 +1662,7 @@ pGenesisVerificationKey = where deserialiseFromHex :: String -> Either String (VerificationKey GenesisKey) deserialiseFromHex = - first (\e -> prettyToString $ "Invalid genesis verification key: " <> prettyError e) + first (\e -> docToString $ "Invalid genesis verification key: " <> prettyError e) . deserialiseFromRawBytesHex (AsVerificationKey AsGenesisKey) . BSC.pack @@ -1701,7 +1701,7 @@ pGenesisDelegateVerificationKeyHash = deserialiseFromHex = first (\e -> - prettyToString $ "Invalid genesis delegate verification key hash: " <> prettyError e) + docToString $ "Invalid genesis delegate verification key hash: " <> prettyError e) . deserialiseFromRawBytesHex (AsHash AsGenesisDelegateKey) . BSC.pack @@ -1745,15 +1745,15 @@ pKesVerificationKey = Right res -> Right res -- The input was valid Bech32, but some other error occurred. - Left err@(Bech32UnexpectedPrefix _ _) -> Left (prettyToString $ prettyError err) - Left err@(Bech32DataPartToBytesError _) -> Left (prettyToString $ prettyError err) - Left err@(Bech32DeserialiseFromBytesError _) -> Left (prettyToString $ prettyError err) - Left err@(Bech32WrongPrefix _ _) -> Left (prettyToString $ prettyError err) + Left err@(Bech32UnexpectedPrefix _ _) -> Left (docToString $ prettyError err) + Left err@(Bech32DataPartToBytesError _) -> Left (docToString $ prettyError err) + Left err@(Bech32DeserialiseFromBytesError _) -> Left (docToString $ prettyError err) + Left err@(Bech32WrongPrefix _ _) -> Left (docToString $ prettyError err) -- The input was not valid Bech32. Attempt to deserialise it as hex. Left (Bech32DecodingError _) -> first - (\e -> prettyToString $ "Invalid stake pool verification key: " <> prettyError e) $ + (\e -> docToString $ "Invalid stake pool verification key: " <> prettyError e) $ deserialiseFromRawBytesHex asType (BSC.pack str) pKesVerificationKeyFile :: Parser (VerificationKeyFile In) @@ -2318,7 +2318,7 @@ pVrfVerificationKeyHash = where deserialiseFromHex :: String -> Either String (Hash VrfKey) deserialiseFromHex = - first (\e -> prettyToString $ "Invalid VRF verification key hash: " <> prettyError e) + first (\e -> docToString $ "Invalid VRF verification key hash: " <> prettyError e) . deserialiseFromRawBytesHex (AsHash AsVrfKey) . BSC.pack @@ -2535,7 +2535,7 @@ pStakePoolMetadataHash = where metadataHash :: String -> Either String (Hash StakePoolMetadata) metadataHash = - first (prettyToString . prettyError) + first (docToString . prettyError) . deserialiseFromRawBytesHex (AsHash AsStakePoolMetadata) . BSC.pack diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs index 7b9114c19b..076dbb831a 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs @@ -50,6 +50,7 @@ import Cardano.CLI.EraBased.Run.Genesis (readAndDecodeShelleyGenesis) import Cardano.CLI.Helpers import Cardano.CLI.Read 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 @@ -264,7 +265,7 @@ runQueryTipCmd } mLocalState <- hushM (first QueryCmdAcquireFailure eLocalState) $ \e -> - liftIO . LT.hPutStrLn IO.stderr $ prettyToLazyText $ "Warning: Local state unavailable: " <> renderQueryCmdError e + liftIO . LT.hPutStrLn IO.stderr $ docToLazyText $ "Warning: Local state unavailable: " <> renderQueryCmdError e chainTip <- pure (mLocalState >>= O.mChainTip) -- The chain tip is unavailable via local state query because we are connecting with an older @@ -280,7 +281,7 @@ runQueryTipCmd localStateOutput <- forM mLocalState $ \localState -> do case slotToEpoch tipSlotNo (O.eraHistory localState) of Left e -> do - liftIO . LT.hPutStrLn IO.stderr $ prettyToLazyText $ + liftIO . LT.hPutStrLn IO.stderr $ docToLazyText $ "Warning: Epoch unavailable: " <> renderQueryCmdError (QueryCmdPastHorizon e) return $ O.QueryTipLocalStateOutput { O.localStateChainTip = chainTip @@ -302,7 +303,7 @@ runQueryTipCmd return $ flip (percentage tolerance) nowSeconds tipTimeResult mSyncProgress <- hushM syncProgressResult $ \e -> do - liftIO . LT.hPutStrLn IO.stderr $ prettyToLazyText $ "Warning: Sync progress unavailable: " <> renderQueryCmdError e + liftIO . LT.hPutStrLn IO.stderr $ docToLazyText $ "Warning: Sync progress unavailable: " <> renderQueryCmdError e return $ O.QueryTipLocalStateOutput { O.localStateChainTip = chainTip @@ -404,8 +405,8 @@ runQueryKesPeriodInfoCmd let counterInformation = opCertNodeAndOnDiskCounters onDiskC stateC -- Always render diagnostic information - liftIO . putStrLn $ prettyToString $ renderOpCertIntervalInformation (unFile nodeOpCertFp) opCertIntervalInformation - liftIO . putStrLn $ prettyToString $ renderOpCertNodeAndOnDiskCounterInformation (unFile nodeOpCertFp) counterInformation + liftIO . putStrLn $ docToString $ renderOpCertIntervalInformation (unFile nodeOpCertFp) opCertIntervalInformation + liftIO . putStrLn $ docToString $ renderOpCertNodeAndOnDiskCounterInformation (unFile nodeOpCertFp) counterInformation let qKesInfoOutput = createQueryKesPeriodInfoOutput opCertIntervalInformation counterInformation eInfo gParams kesPeriodInfoJSON = encodePretty qKesInfoOutput @@ -631,7 +632,9 @@ runQueryPoolStateCmd sbe <- requireShelleyBasedEra era & onNothing (left QueryCmdByronEra) - result <- lift (queryPoolState sbe $ Just $ Set.fromList poolIds) + beo <- requireEon BabbageEra era + + result <- lift (queryPoolState beo $ Just $ Set.fromList poolIds) & onLeft (left . QueryCmdUnsupportedNtcVersion) & onLeft (left . QueryCmdLocalStateQueryError . EraMismatchError) @@ -711,7 +714,9 @@ runQueryStakeSnapshotCmd All -> Nothing Only poolIds -> Just $ Set.fromList poolIds - result <- lift (queryStakeSnapshot sbe poolFilter) + beo <- requireEon BabbageEra era + + result <- lift (queryStakeSnapshot beo poolFilter) & onLeft (left . QueryCmdUnsupportedNtcVersion) & onLeft (left . QueryCmdLocalStateQueryError . EraMismatchError) @@ -810,14 +815,17 @@ runQueryStakeAddressInfoCmd & onLeft (left . QueryCmdUnsupportedNtcVersion) & onLeft (left . QueryCmdLocalStateQueryError . EraMismatchError) - stakeDelegDeposits <- lift (queryStakeDelegDeposits sbe stakeAddr) + beo <- requireEon BabbageEra era + + stakeDelegDeposits <- lift (queryStakeDelegDeposits beo stakeAddr) & onLeft (left . QueryCmdUnsupportedNtcVersion) & onLeft (left . QueryCmdLocalStateQueryError . EraMismatchError) - stakeVoteDelegatees <- monoidForEraInEonA era $ \(_ :: ConwayEraOnwards era) -> - lift (queryStakeVoteDelegatees sbe stakeAddr) - & onLeft (left . QueryCmdUnsupportedNtcVersion) - & onLeft (left . QueryCmdLocalStateQueryError . EraMismatchError) + ceo <- requireEon ConwayEra era + + stakeVoteDelegatees <- lift (queryStakeVoteDelegatees ceo stakeAddr) + & onLeft (left . QueryCmdUnsupportedNtcVersion) + & onLeft (left . QueryCmdLocalStateQueryError . EraMismatchError) return $ do writeStakeAddressInfo @@ -1221,7 +1229,9 @@ runQueryLeadershipScheduleCmd case whichSchedule of CurrentEpoch -> do - serCurrentEpochState <- lift (queryPoolDistribution sbe (Just (Set.singleton poolid))) + beo <- requireEon BabbageEra era + + serCurrentEpochState <- lift (queryPoolDistribution beo (Just (Set.singleton poolid))) & onLeft (left . QueryCmdUnsupportedNtcVersion) & onLeft (left . QueryCmdLocalStateQueryError . EraMismatchError) @@ -1338,9 +1348,7 @@ runQueryConstitution , Cmd.mOutFile } = conwayEraOnwardsConstraints eon $ do let localNodeConnInfo = LocalNodeConnectInfo consensusModeParams networkId nodeSocketPath - sbe = conwayEraOnwardsToShelleyBasedEra eon - - constitution <- runQuery localNodeConnInfo $ queryConstitution sbe + constitution <- runQuery localNodeConnInfo $ queryConstitution eon writeOutput mOutFile constitution runQueryGovState @@ -1355,9 +1363,7 @@ runQueryGovState , Cmd.mOutFile } = conwayEraOnwardsConstraints eon $ do let localNodeConnInfo = LocalNodeConnectInfo consensusModeParams networkId nodeSocketPath - sbe = conwayEraOnwardsToShelleyBasedEra eon - - govState <- runQuery localNodeConnInfo $ queryGovState sbe + govState <- runQuery localNodeConnInfo $ queryGovState eon writeOutput mOutFile govState runQueryDRepState @@ -1373,11 +1379,10 @@ runQueryDRepState , Cmd.mOutFile } = conwayEraOnwardsConstraints eon $ do let localNodeConnInfo = LocalNodeConnectInfo consensusModeParams networkId nodeSocketPath - sbe = conwayEraOnwardsToShelleyBasedEra eon drepCreds <- Set.fromList <$> mapM (firstExceptT QueryCmdDRepKeyError . getDRepCredentialFromVerKeyHashOrFile) drepKeys - drepState <- runQuery localNodeConnInfo $ queryDRepState sbe drepCreds + drepState <- runQuery localNodeConnInfo $ queryDRepState eon drepCreds writeOutput mOutFile $ second drepStateToJson <$> Map.assocs drepState where @@ -1400,14 +1405,13 @@ runQueryDRepStakeDistribution , Cmd.mOutFile } = conwayEraOnwardsConstraints eon $ do let localNodeConnInfo = LocalNodeConnectInfo consensusModeParams networkId nodeSocketPath - sbe = conwayEraOnwardsToShelleyBasedEra eon let drepFromVrfKey = fmap Ledger.DRepCredential . firstExceptT QueryCmdDRepKeyError . getDRepCredentialFromVerKeyHashOrFile dreps <- Set.fromList <$> mapM drepFromVrfKey drepKeys - drepStakeDistribution <- runQuery localNodeConnInfo $ queryDRepStakeDistribution sbe dreps + drepStakeDistribution <- runQuery localNodeConnInfo $ queryDRepStakeDistribution eon dreps writeOutput mOutFile $ Map.assocs drepStakeDistribution @@ -1426,7 +1430,6 @@ runQueryCommitteeMembersState , Cmd.memberStatuses = memberStatuses } = conwayEraOnwardsConstraints eon $ do let localNodeConnInfo = LocalNodeConnectInfo consensusModeParams networkId nodeSocketPath - sbe = conwayEraOnwardsToShelleyBasedEra eon let coldKeysFromVerKeyHashOrFile = firstExceptT QueryCmdCommitteeColdKeyError . getCommitteeColdCredentialFromVerKeyHashOrFile @@ -1437,7 +1440,7 @@ runQueryCommitteeMembersState hotKeys <- Set.fromList <$> mapM hotKeysFromVerKeyHashOrFile hotCredKeys committeeState <- runQuery localNodeConnInfo $ - queryCommitteeMembersState sbe coldKeys hotKeys (Set.fromList memberStatuses) + queryCommitteeMembersState eon coldKeys hotKeys (Set.fromList memberStatuses) writeOutput mOutFile $ A.toJSON committeeState runQuery :: LocalNodeConnectInfo @@ -1517,3 +1520,14 @@ utcTimeToSlotNo nodeSocketPath consensusModeParams networkId utcTime = do ) & onLeft (left . QueryCmdAcquireFailure) & onLeft left + + +requireEon :: forall eon era minEra m. (Eon eon, Monad m) + => CardanoEra minEra -- ^ minimal required era i.e. for 'ConwayEraOnwards' eon it's 'Conway' + -> CardanoEra era -- ^ node era + -> ExceptT QueryCmdError m (eon era) +-- TODO: implement 'Bounded' for `Some eon` and remove 'minEra' +requireEon minEra era = + hoistMaybe + (QueryCmdLocalStateQueryError $ mkEraMismatchError NodeEraMismatchError { nodeEra = era, era = minEra }) + (forEraMaybeEon era) diff --git a/cardano-cli/src/Cardano/CLI/Pretty.hs b/cardano-cli/src/Cardano/CLI/Pretty.hs index d9a5fa98e1..1e8e0c9150 100644 --- a/cardano-cli/src/Cardano/CLI/Pretty.hs +++ b/cardano-cli/src/Cardano/CLI/Pretty.hs @@ -23,7 +23,7 @@ consoleBracket :: IO a -> IO a consoleBracket = bracket_ (IO.waitQSem sem) (IO.signalQSem sem) putLn :: MonadIO m => Doc AnsiStyle -> m () -putLn = liftIO . consoleBracket . TextLazy.putStrLn . prettyToLazyText +putLn = liftIO . consoleBracket . TextLazy.putStrLn . docToLazyText hPutLn :: MonadIO m => IO.Handle -> Doc AnsiStyle -> m () -hPutLn h = liftIO . consoleBracket . TextLazy.hPutStr h . prettyToLazyText +hPutLn h = liftIO . consoleBracket . TextLazy.hPutStr h . docToLazyText diff --git a/cardano-cli/src/Cardano/CLI/Read.hs b/cardano-cli/src/Cardano/CLI/Read.hs index a8e701e1a2..4c1eafe2ec 100644 --- a/cardano-cli/src/Cardano/CLI/Read.hs +++ b/cardano-cli/src/Cardano/CLI/Read.hs @@ -234,7 +234,7 @@ renderScriptWitnessError = \case prettyError err ScriptWitnessErrorScriptLanguageNotSupportedInEra (AnyScriptLanguage lang) anyEra -> "The script language " <> pshow lang <> " is not supported in the " <> - pretty (renderEra anyEra) <> " era." + pretty anyEra <> " era." ScriptWitnessErrorExpectedSimple file (AnyScriptLanguage lang) -> pretty file <> ": expected a script in the simple script language, " <> "but it is actually using " <> pshow lang <> ". Alternatively, to use " <> @@ -244,7 +244,7 @@ renderScriptWitnessError = \case pretty file <> ": expected a script in the Plutus script language, " <> "but it is actually using " <> pshow lang <> "." ScriptWitnessErrorReferenceScriptsNotSupportedInEra anyEra -> - "Reference scripts not supported in era: " <> pretty (renderEra anyEra) + "Reference scripts not supported in era: " <> pretty anyEra ScriptWitnessErrorScriptData sDataError -> renderScriptDataError sDataError diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdLocalStateQueryError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdLocalStateQueryError.hs index 47b2f271c8..5df2ebb9bf 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdLocalStateQueryError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdLocalStateQueryError.hs @@ -1,12 +1,15 @@ {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-} module Cardano.CLI.Types.Errors.QueryCmdLocalStateQueryError ( QueryCmdLocalStateQueryError(..) + , mkEraMismatchError , renderLocalStateQueryError ) where import Cardano.Api.Pretty +import Cardano.CLI.Types.Errors.NodeEraMismatchError import Ouroboros.Consensus.Cardano.Block (EraMismatch (..)) -- | An error that can occur while querying a node's local state. @@ -16,6 +19,11 @@ newtype QueryCmdLocalStateQueryError -- 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 -> diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddressDelegationError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddressDelegationError.hs index aa6eb4c44e..56759c6a50 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddressDelegationError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddressDelegationError.hs @@ -8,13 +8,8 @@ module Cardano.CLI.Types.Errors.StakeAddressDelegationError import Cardano.Api import Cardano.Api.Pretty -import qualified Data.Text as Text - newtype StakeAddressDelegationError = VoteDelegationNotSupported (EraInEon ShelleyToBabbageEra) deriving Show instance Error StakeAddressDelegationError where prettyError = \case - VoteDelegationNotSupported (EraInEon eraInEon) -> "Vote delegation not supported in " <> pshow eraTxt <> " era." - where - cEra = toCardanoEra eraInEon - eraTxt = cardanoEraConstraints cEra $ Text.unpack . renderEra $ AnyCardanoEra cEra + VoteDelegationNotSupported (EraInEon eraInEon) -> "Vote delegation not supported in " <> pretty (toCardanoEra eraInEon) <> " era." diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs index df6a96d4bd..35fee53f87 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs @@ -110,13 +110,13 @@ renderTxCmdError = \case renderBootstrapWitnessError sbwErr TxCmdTxFeatureMismatch era TxFeatureImplicitFees -> "An explicit transaction fee must be specified for " <> - pretty (renderEra era) <> " era transactions." + pretty era <> " era transactions." TxCmdTxFeatureMismatch (AnyCardanoEra ShelleyEra) TxFeatureValidityNoUpperBound -> "A TTL must be specified for Shelley era transactions." TxCmdTxFeatureMismatch era feature -> - pretty (renderFeature feature) <> " cannot be used for " <> pretty (renderEra era) <> + pretty (renderFeature feature) <> " cannot be used for " <> pretty era <> " era transactions." TxCmdTxBodyError err' -> @@ -127,8 +127,8 @@ renderTxCmdError = \case TxCmdWitnessEraMismatch era era' (WitnessFile file) -> "The era of a witness does not match the era of the transaction. " <> - "The transaction is for the " <> pretty (renderEra era) <> " era, but the " <> - "witness in " <> pshow file <> " is for the " <> pretty (renderEra era') <> " era." + "The transaction is for the " <> pretty era <> " era, but the " <> + "witness in " <> pshow file <> " is for the " <> pretty era' <> " era." TxCmdPolicyIdsMissing policyids -> mconcat @@ -170,8 +170,8 @@ renderTxCmdError = \case TxCmdTxNodeEraMismatchError (NodeEraMismatchError { NEM.era = valueEra, nodeEra = nodeEra }) -> cardanoEraConstraints nodeEra $ cardanoEraConstraints valueEra $ mconcat [ "Transactions can only be produced in the same era as the node. Requested era: " - , pretty (renderEra (AnyCardanoEra valueEra)) <> ", node era: " - , pretty (renderEra (AnyCardanoEra nodeEra)) <> "." + , pretty valueEra <> ", node era: " + , pretty nodeEra <> "." ] TxCmdQueryConvenienceError e -> pretty $ renderQueryConvenienceError e diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs index 9b2cb8f033..28c312df4f 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs @@ -54,7 +54,7 @@ instance Error ScriptLanguageValidationError where prettyError = \case ScriptLanguageValidationError lang era -> "The script language " <> pshow lang <> " is not supported in the " <> - pretty (renderEra era) <> " era." + pretty era <> " era." validateScriptSupportedInEra :: ShelleyBasedEra era @@ -74,9 +74,9 @@ data TxFeeValidationError instance Error TxFeeValidationError where prettyError (TxFeatureImplicitFeesE era) = - "Implicit transaction fee not supported in " <> pretty (renderEra era) + "Implicit transaction fee not supported in " <> pretty era prettyError (TxFeatureExplicitFeesE era) = - "Explicit transaction fee not supported in " <> pretty (renderEra era) + "Explicit transaction fee not supported in " <> pretty era validateTxFee :: CardanoEra era -> Maybe Lovelace @@ -99,7 +99,7 @@ newtype TxTotalCollateralValidationError instance Error TxTotalCollateralValidationError where prettyError (TxTotalCollateralNotSupported era) = - "Transaction collateral not supported in " <> pretty (renderEra era) + "Transaction collateral not supported in " <> pretty era validateTxTotalCollateral :: CardanoEra era -> Maybe Lovelace @@ -115,7 +115,7 @@ newtype TxReturnCollateralValidationError instance Error TxReturnCollateralValidationError where prettyError (TxReturnCollateralNotSupported era) = - "Transaction return collateral not supported in " <> pretty (renderEra era) + "Transaction return collateral not supported in " <> pretty era validateTxReturnCollateral :: CardanoEra era -> Maybe (TxOut CtxTx era) @@ -131,7 +131,7 @@ newtype TxValidityLowerBoundValidationError instance Error TxValidityLowerBoundValidationError where prettyError (TxValidityLowerBoundNotSupported era) = - "Transaction validity lower bound not supported in " <> pretty (renderEra era) + "Transaction validity lower bound not supported in " <> pretty era validateTxValidityLowerBound :: CardanoEra era @@ -148,7 +148,7 @@ newtype TxValidityUpperBoundValidationError instance Error TxValidityUpperBoundValidationError where prettyError (TxValidityUpperBoundNotSupported era) = - "Transaction validity upper bound must be specified in " <> pretty (renderEra era) + "Transaction validity upper bound must be specified in " <> pretty era validateTxValidityUpperBound :: CardanoEra era @@ -169,7 +169,7 @@ data TxAuxScriptsValidationError instance Error TxAuxScriptsValidationError where prettyError (TxAuxScriptsNotSupportedInEra era) = - "Transaction auxiliary scripts are not supported in " <> pretty (renderEra era) + "Transaction auxiliary scripts are not supported in " <> pretty era prettyError (TxAuxScriptsLanguageError e) = "Transaction auxiliary scripts error: " <> prettyError e @@ -189,7 +189,7 @@ newtype TxRequiredSignersValidationError instance Error TxRequiredSignersValidationError where prettyError (TxRequiredSignersValidationError e) = - "Transaction required signers are not supported in " <> pretty (renderEra e) + "Transaction required signers are not supported in " <> pretty e validateRequiredSigners :: CardanoEra era @@ -206,7 +206,7 @@ newtype TxWithdrawalsValidationError instance Error TxWithdrawalsValidationError where prettyError (TxWithdrawalsNotSupported e) = - "Transaction withdrawals are not supported in " <> pretty (renderEra e) + "Transaction withdrawals are not supported in " <> pretty e validateTxWithdrawals :: forall era. @@ -233,7 +233,7 @@ newtype TxCertificatesValidationError instance Error TxCertificatesValidationError where prettyError (TxCertificatesValidationNotSupported e) = - "Transaction certificates are not supported in " <> pretty (renderEra e) + "Transaction certificates are not supported in " <> pretty e validateTxCertificates :: forall era. @@ -262,7 +262,7 @@ newtype TxProtocolParametersValidationError instance Error TxProtocolParametersValidationError where prettyError (ProtocolParametersNotSupported e) = - "Transaction protocol parameters are not supported in " <> pretty (renderEra e) + "Transaction protocol parameters are not supported in " <> pretty e validateProtocolParameters :: CardanoEra era @@ -279,7 +279,7 @@ newtype TxUpdateProposalValidationError instance Error TxUpdateProposalValidationError where prettyError (TxUpdateProposalNotSupported e) = - "Transaction update proposal is not supported in " <> pretty (renderEra e) + "Transaction update proposal is not supported in " <> pretty e newtype TxScriptValidityValidationError = ScriptValidityNotSupported AnyCardanoEra @@ -287,7 +287,7 @@ newtype TxScriptValidityValidationError instance Error TxScriptValidityValidationError where prettyError (ScriptValidityNotSupported e) = - "Transaction script validity is not supported in " <> pretty (renderEra e) + "Transaction script validity is not supported in " <> pretty e validateTxScriptValidity :: CardanoEra era diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Byron/Tx.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Byron/Tx.hs index 0bc4f0d6f9..85d1356634 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Byron/Tx.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Byron/Tx.hs @@ -60,7 +60,7 @@ getTxByteString :: FilePath -> H.PropertyT IO (ATxAux ByteString) getTxByteString txFp = do eATxAuxBS <- liftIO . runExceptT $ readByronTx $ File txFp case eATxAuxBS of - Left err -> failWith Nothing . prettyToString $ renderByronTxError err + Left err -> failWith Nothing . docToString $ renderByronTxError err Right aTxAuxBS -> return aTxAuxBS compareByronTxs :: FilePath -> FilePath -> H.PropertyT IO () diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Byron/UpdateProposal.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Byron/UpdateProposal.hs index f948ceb399..fc53082187 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Byron/UpdateProposal.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Byron/UpdateProposal.hs @@ -39,12 +39,12 @@ hprop_byron_update_proposal = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir eExpected <- liftIO . runExceptT $ readByronUpdateProposal expectedUpdateProposal expected <- case eExpected of - Left err -> failWith Nothing . prettyToString $ renderByronUpdateProposalError err + Left err -> failWith Nothing . docToString $ renderByronUpdateProposalError err Right prop -> return prop eCreated <- liftIO . runExceptT $ readByronUpdateProposal createdUpdateProposal created <- case eCreated of - Left err -> failWith Nothing . prettyToString $ renderByronUpdateProposalError err + Left err -> failWith Nothing . docToString $ renderByronUpdateProposalError err Right prop -> return prop expected === created diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Byron/Vote.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Byron/Vote.hs index 7cd5d62809..7330d04062 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Byron/Vote.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Byron/Vote.hs @@ -35,12 +35,12 @@ hprop_byron_yes_vote = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do eExpected <- liftIO . runExceptT $ readByronVote expectedYesVote expected <- case eExpected of - Left err -> failWith Nothing . prettyToString $ renderByronVoteError err + Left err -> failWith Nothing . docToString $ renderByronVoteError err Right prop -> return prop eCreated <- liftIO . runExceptT $ readByronVote createdYesVote created <- case eCreated of - Left err -> failWith Nothing . prettyToString $ renderByronVoteError err + Left err -> failWith Nothing . docToString $ renderByronVoteError err Right prop -> return prop expected === created @@ -62,12 +62,12 @@ hprop_byron_no_vote = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do eExpected <- liftIO . runExceptT $ readByronVote expectedNoVote expected <- case eExpected of - Left err -> failWith Nothing . prettyToString $ renderByronVoteError err + Left err -> failWith Nothing . docToString $ renderByronVoteError err Right prop -> return prop eCreated <- liftIO . runExceptT $ readByronVote createdNoVote created <- case eCreated of - Left err -> failWith Nothing . prettyToString $ renderByronVoteError err + Left err -> failWith Nothing . docToString $ renderByronVoteError err Right prop -> return prop expected === created diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/VerifyPoll.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/VerifyPoll.hs index 0d3d476e06..5d41312374 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/VerifyPoll.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/VerifyPoll.hs @@ -36,7 +36,7 @@ hprop_golden_governanceVerifyPoll = propertyOnce $ do liftIO (readVerificationKeyOrTextEnvFile AsStakePoolKey goldenVkFile) >>= \case Left e -> - H.failWith Nothing $ prettyToString $ prettyError e + H.failWith Nothing $ docToString $ prettyError e Right vk -> do let expected = prettyPrintJSON $ serialiseToRawBytesHexText <$> [verificationKeyHash vk] H.assert $ expected `BSC.isInfixOf` stdout diff --git a/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Util.hs b/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Util.hs index 5a55cdfe26..3a472e4c9d 100644 --- a/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Util.hs +++ b/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Util.hs @@ -143,7 +143,7 @@ checkTextEnvelopeFormat tve reference created = GHC.withFrozenCallStack $ do Right refTextEnvelope -> return refTextEnvelope Left fileErr -> - failWithCustom GHC.callStack Nothing . (prettyToString . prettyError) $ fileErr + failWithCustom GHC.callStack Nothing . (docToString . prettyError) $ fileErr typeTitleEquivalence :: (MonadTest m, HasCallStack) => TextEnvelope -> TextEnvelope -> m () typeTitleEquivalence (TextEnvelope refType refTitle _)