Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define Functor instance for FileError #5057

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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