1 module Data.Gargantext.Error where
3 import Control.Exception (Exception)
4 import Data.Typeable (Typeable)
5 import GHC.Generics (Generic)
6 import Network.HTTP.Client (HttpException)
8 import System.Exit (ExitCode (..), exitWith)
9 import System.IO (stderr)
10 --import Text.Parsec.Error
11 --import Text.Parsec.Pos hiding (Line)
14 data GargError = GargIOError String IOError
15 | GargHttpError String HttpException
16 | GargParseError String
17 | GargNgramsError String
18 | GargDatabaseError String
19 deriving (Show, Typeable, Generic)
22 instance Exception PandocError
24 -- | Handle GargError by exiting with an error message.
25 handleError :: Either GargError a -> IO a
26 handleError (Right r) = pure r
27 handleError (Left e) =
29 GargIOError _ err' -> ioError err'
30 GargHttpError u err' -> err 61 $
31 "Could not fetch " ++ u ++ "\n" ++ show err'
32 GargParseError s -> err 64 s
36 err :: Int -> String -> IO a
38 UTF8.hPutStrLn stderr msg
39 exitWith $ ExitFailure exitCode