Skip to content

Commit

Permalink
Define Functor instance for FileError
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Apr 6, 2023
1 parent 27f8437 commit 140c7a5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
5 changes: 3 additions & 2 deletions cardano-api/src/Cardano/Api/Error.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GADTSyntax #-}

Expand Down Expand Up @@ -38,15 +39,15 @@ 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
FilePath
-- ^ 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)=
Expand Down
13 changes: 1 addition & 12 deletions cardano-api/src/Cardano/Api/Keys/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 140c7a5

Please sign in to comment.