diff --git a/cardano-api/src/Cardano/Api/Error.hs b/cardano-api/src/Cardano/Api/Error.hs index 56ee024b26b..437ad14c4ec 100644 --- a/cardano-api/src/Cardano/Api/Error.hs +++ b/cardano-api/src/Cardano/Api/Error.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE GADTSyntax #-} @@ -38,7 +39,7 @@ instance Exception ErrorAsException where displayException (ErrorAsException e) = displayError e -data FileError e = FileError FilePath e +data FileError e = FileError FilePath e | FileErrorTempFile FilePath -- ^ Target path @@ -46,7 +47,7 @@ data FileError e = FileError FilePath e -- ^ Temporary path Handle | FileIOError FilePath IOException - deriving (Show, Eq) + deriving (Show, Eq, Functor) instance Error e => Error (FileError e) where displayError (FileErrorTempFile targetPath tempPath h)= diff --git a/cardano-api/src/Cardano/Api/Keys/Read.hs b/cardano-api/src/Cardano/Api/Keys/Read.hs index 485e125a835..8570843b064 100644 --- a/cardano-api/src/Cardano/Api/Keys/Read.hs +++ b/cardano-api/src/Cardano/Api/Keys/Read.hs @@ -49,18 +49,7 @@ readKeyFileTextEnvelope -> FilePath -> IO (Either (FileError InputDecodeError) a) readKeyFileTextEnvelope asType fp = - first toInputDecodeError <$> readFileTextEnvelope asType fp - where - toInputDecodeError - :: FileError TextEnvelopeError - -> FileError InputDecodeError - toInputDecodeError err = - case err of - FileIOError path ex -> FileIOError path ex - FileError path textEnvErr -> - FileError path (InputTextEnvelopeError textEnvErr) - FileErrorTempFile targetP tempP h -> - FileErrorTempFile targetP tempP h + first (fmap InputTextEnvelopeError) <$> readFileTextEnvelope asType fp -- | Read a cryptographic key from a file given that it is one of the provided -- types.