1
{-# LANGUAGE ExistentialQuantification #-}
2
{-# LANGUAGE GADTSyntax #-}
4
-- | Class of errors used in the Api.
6
module Cardano.Api.Error
8
, throwErrorAsException
15
import Control.Exception (Exception(..), IOException, throwIO)
16
import System.IO (Handle)
19
class Show e => Error e where
21
displayError :: e -> String
23
instance Error () where
27
-- | The preferred approach is to use 'Except' or 'ExceptT', but you can if
28
-- necessary use IO exceptions.
30
throwErrorAsException :: Error e => e -> IO a
31
throwErrorAsException e = throwIO (ErrorAsException e)
33
data ErrorAsException where
34
ErrorAsException :: Error e => e -> ErrorAsException
36
instance Show ErrorAsException where
37
show (ErrorAsException e) = show e
39
instance Exception ErrorAsException where
40
displayException (ErrorAsException e) = displayError e
43
data FileError e = FileError FilePath e
50
| FileIOError FilePath IOException
53
instance Error e => Error (FileError e) where
54
displayError (FileErrorTempFile targetPath tempPath h)=
55
"Error creating temporary file at: " ++ tempPath ++
56
"/n" ++ "Target path: " ++ targetPath ++
57
"/n" ++ "Handle: " ++ show h
58
displayError (FileIOError path ioe) =
59
path ++ ": " ++ displayException ioe
60
displayError (FileError path e) =
61
path ++ ": " ++ displayError e