From 01ecbd3123abdabfc74688c1897cce50de5fa5af Mon Sep 17 00:00:00 2001 From: John Ky Date: Fri, 18 Aug 2023 21:22:54 +1000 Subject: [PATCH] Move StakeAddressDelegationError StakeAddressRegistrationError and ShelleyStakeAddressCmdError error types to own modules --- cardano-cli/cardano-cli.cabal | 4 +- .../Cardano/CLI/EraBased/Run/Certificate.hs | 3 +- .../Cardano/CLI/Legacy/Run/StakeAddress.hs | 4 +- .../Errors/ShelleyStakeAddressCmdError.hs | 27 ++++++++++ .../Cardano/CLI/Types/Errors/StakeAddress.hs | 50 ------------------- .../Errors/StakeAddressDelegationError.hs | 21 ++++++++ .../Errors/StakeAddressRegistrationError.hs | 14 ++++++ .../Test/Golden/ErrorsSpec.hs | 4 +- 8 files changed, 73 insertions(+), 54 deletions(-) create mode 100644 cardano-cli/src/Cardano/CLI/Types/Errors/ShelleyStakeAddressCmdError.hs delete mode 100644 cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddress.hs create mode 100644 cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddressDelegationError.hs create mode 100644 cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddressRegistrationError.hs diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index bd109da221..c5971d7b70 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -121,7 +121,9 @@ library Cardano.CLI.Types.Common Cardano.CLI.Types.Errors.GovernanceCmdError Cardano.CLI.Types.Errors.ScriptDecodeError - Cardano.CLI.Types.Errors.StakeAddress + Cardano.CLI.Types.Errors.ShelleyStakeAddressCmdError + Cardano.CLI.Types.Errors.StakeAddressDelegationError + Cardano.CLI.Types.Errors.StakeAddressRegistrationError Cardano.CLI.Types.Governance Cardano.CLI.Types.Key Cardano.CLI.Types.Output diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Certificate.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Certificate.hs index d243038617..d4bcc7aa18 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Certificate.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Certificate.hs @@ -24,7 +24,8 @@ import Cardano.Api.Shelley import Cardano.CLI.Read import Cardano.CLI.Types.Common -import Cardano.CLI.Types.Errors.StakeAddress +import Cardano.CLI.Types.Errors.ShelleyStakeAddressCmdError +import Cardano.CLI.Types.Errors.StakeAddressRegistrationError import Cardano.CLI.Types.Key import Control.Monad.Trans.Class diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Run/StakeAddress.hs b/cardano-cli/src/Cardano/CLI/Legacy/Run/StakeAddress.hs index a6a94a62b6..9d2734c205 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Run/StakeAddress.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Run/StakeAddress.hs @@ -22,7 +22,9 @@ import Cardano.Api.Shelley import Cardano.CLI.EraBased.Run.Certificate import Cardano.CLI.Legacy.Commands.StakeAddress import Cardano.CLI.Types.Common -import Cardano.CLI.Types.Errors.StakeAddress +import Cardano.CLI.Types.Errors.ShelleyStakeAddressCmdError +import Cardano.CLI.Types.Errors.StakeAddressDelegationError +import Cardano.CLI.Types.Errors.StakeAddressRegistrationError import Cardano.CLI.Types.Key (DelegationTarget (..), StakeIdentifier (..), StakeVerifier (..), VerificationKeyOrFile, readVerificationKeyOrFile, readVerificationKeyOrHashOrFile) diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/ShelleyStakeAddressCmdError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/ShelleyStakeAddressCmdError.hs new file mode 100644 index 0000000000..4589575d1c --- /dev/null +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/ShelleyStakeAddressCmdError.hs @@ -0,0 +1,27 @@ +{-# LANGUAGE LambdaCase #-} + +module Cardano.CLI.Types.Errors.ShelleyStakeAddressCmdError + ( ShelleyStakeAddressCmdError(..) + ) where + +import Cardano.Api + +import Cardano.CLI.Read +import Cardano.CLI.Types.Errors.StakeAddressDelegationError +import Cardano.CLI.Types.Errors.StakeAddressRegistrationError + +data ShelleyStakeAddressCmdError + = ShelleyStakeAddressCmdReadKeyFileError !(FileError InputDecodeError) + | ShelleyStakeAddressCmdReadScriptFileError !(FileError ScriptDecodeError) + | ShelleyStakeAddressCmdWriteFileError !(FileError ()) + | StakeRegistrationError !StakeAddressRegistrationError + | StakeDelegationError !StakeAddressDelegationError + deriving Show + +instance Error ShelleyStakeAddressCmdError where + displayError = \case + ShelleyStakeAddressCmdReadKeyFileError fileErr -> displayError fileErr + ShelleyStakeAddressCmdWriteFileError fileErr -> displayError fileErr + ShelleyStakeAddressCmdReadScriptFileError fileErr -> displayError fileErr + StakeRegistrationError regErr -> displayError regErr + StakeDelegationError delegErr -> displayError delegErr diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddress.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddress.hs deleted file mode 100644 index ab4f63d155..0000000000 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddress.hs +++ /dev/null @@ -1,50 +0,0 @@ -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE RankNTypes #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeApplications #-} - -module Cardano.CLI.Types.Errors.StakeAddress - ( ShelleyStakeAddressCmdError(..) - , StakeAddressRegistrationError(..) - , StakeAddressDelegationError(..) - ) where - -import Cardano.Api - -import Cardano.CLI.Read - -import qualified Data.Text as Text - -data ShelleyStakeAddressCmdError - = ShelleyStakeAddressCmdReadKeyFileError !(FileError InputDecodeError) - | ShelleyStakeAddressCmdReadScriptFileError !(FileError ScriptDecodeError) - | ShelleyStakeAddressCmdWriteFileError !(FileError ()) - | StakeRegistrationError !StakeAddressRegistrationError - | StakeDelegationError !StakeAddressDelegationError - deriving Show - - -instance Error ShelleyStakeAddressCmdError where - displayError = \case - ShelleyStakeAddressCmdReadKeyFileError fileErr -> displayError fileErr - ShelleyStakeAddressCmdWriteFileError fileErr -> displayError fileErr - ShelleyStakeAddressCmdReadScriptFileError fileErr -> displayError fileErr - StakeRegistrationError regErr -> displayError regErr - StakeDelegationError delegErr -> displayError delegErr - -data StakeAddressRegistrationError = StakeAddressRegistrationDepositRequired deriving Show - -instance Error StakeAddressRegistrationError where - displayError = \case - StakeAddressRegistrationDepositRequired -> "Stake address deposit required." - -newtype StakeAddressDelegationError = VoteDelegationNotSupported AnyShelleyToBabbageEra deriving Show - -instance Error StakeAddressDelegationError where - displayError = \case - VoteDelegationNotSupported (AnyShelleyToBabbageEra stbe) -> "Vote delegation not supported in " <> eraTxt stbe <> " era." - where - eraTxt :: forall era. ShelleyToBabbageEra era -> String - eraTxt stbe' = shelleyToBabbageEraConstraints stbe' $ - Text.unpack . renderEra $ AnyCardanoEra (cardanoEra @era) - diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddressDelegationError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddressDelegationError.hs new file mode 100644 index 0000000000..8de937f6b0 --- /dev/null +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddressDelegationError.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeApplications #-} + +module Cardano.CLI.Types.Errors.StakeAddressDelegationError + ( StakeAddressDelegationError(..) + ) where + +import Cardano.Api + +import qualified Data.Text as Text + +newtype StakeAddressDelegationError = VoteDelegationNotSupported AnyShelleyToBabbageEra deriving Show + +instance Error StakeAddressDelegationError where + displayError = \case + VoteDelegationNotSupported (AnyShelleyToBabbageEra stbe) -> "Vote delegation not supported in " <> eraTxt stbe <> " era." + where + eraTxt :: forall era. ShelleyToBabbageEra era -> String + eraTxt stbe' = shelleyToBabbageEraConstraints stbe' $ + Text.unpack . renderEra $ AnyCardanoEra (cardanoEra @era) diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddressRegistrationError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddressRegistrationError.hs new file mode 100644 index 0000000000..9262164bb0 --- /dev/null +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddressRegistrationError.hs @@ -0,0 +1,14 @@ +{-# LANGUAGE LambdaCase #-} + +module Cardano.CLI.Types.Errors.StakeAddressRegistrationError + ( StakeAddressRegistrationError(..) + ) where + +import Cardano.Api + +data StakeAddressRegistrationError = StakeAddressRegistrationDepositRequired + deriving Show + +instance Error StakeAddressRegistrationError where + displayError = \case + StakeAddressRegistrationDepositRequired -> "Stake address deposit required." diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/ErrorsSpec.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/ErrorsSpec.hs index a48ab2a48e..791ad8e570 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/ErrorsSpec.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/ErrorsSpec.hs @@ -19,7 +19,9 @@ import Cardano.CLI.EraBased.Run.Governance.Committee import Cardano.CLI.EraBased.Vote import Cardano.CLI.Read import Cardano.CLI.Types.Errors.GovernanceCmdError -import Cardano.CLI.Types.Errors.StakeAddress +import Cardano.CLI.Types.Errors.ShelleyStakeAddressCmdError +import Cardano.CLI.Types.Errors.StakeAddressDelegationError +import Cardano.CLI.Types.Errors.StakeAddressRegistrationError import Data.Text.Encoding.Error import GHC.Stack (HasCallStack)