diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Hash.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Hash.hs index 29274e9954..61298f390d 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Hash.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Hash.hs @@ -48,16 +48,18 @@ runGovernanceHashCmd Cmd.GovernanceHashCmdArgs { toHash } = -- This can be done in a separate PR case toHash of Cmd.GovernanceHashSourceBinaryFile fp -> do - bytes <- liftIO $ BS.readFile $ unFile fp + let path = unFile fp + bytes <- handleIOExceptT (GovernanceHashReadFileError path) $ BS.readFile path let hash = Ledger.hashAnchorData $ Ledger.AnchorData bytes printHash hash Cmd.GovernanceHashSourceTextFile fp -> do - text <- liftIO $ Text.readFile $ unFile fp + let path = unFile fp + text <- handleIOExceptT (GovernanceHashReadFileError path) $ Text.readFile path let hash = Ledger.hashAnchorData $ Ledger.AnchorData $ Text.encodeUtf8 text printHash hash Cmd.GovernanceHashSourceText text -> do let hash = Ledger.hashAnchorData $ Ledger.AnchorData $ Text.encodeUtf8 text printHash hash where - printHash :: Ledger.SafeHash StandardCrypto i -> ExceptT GovernanceHashError IO () + printHash :: Ledger.SafeHash StandardCrypto i -> ExceptT a IO () printHash = liftIO . putStr . Text.unpack . hashToTextAsHex . extractHash diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceHashError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceHashError.hs index c6070d5dc0..914ad52dd9 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceHashError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceHashError.hs @@ -1,15 +1,17 @@ +{-# LANGUAGE LambdaCase #-} module Cardano.CLI.Types.Errors.GovernanceHashError ( GovernanceHashError(..) ) where import Cardano.Api -import Cardano.Prelude (UnicodeException) +import Cardano.Prelude (Exception (displayException), IOException) data GovernanceHashError - = GovernanceHashReadFileError (FileError InputDecodeError) - | GovernanceHashUnicodeError UnicodeException + = GovernanceHashReadFileError FilePath IOException deriving Show instance Error GovernanceHashError where - displayError = undefined + displayError = \case + GovernanceHashReadFileError filepath exc -> + "Cannot read " <> filepath <> ": " <> displayException exc