-- |A simple feed generator: Error handling -- -- Copyright (c) 2006 Manuel M T Chakravarty -- -- License: -- --- Description --------------------------------------------------------------- -- -- Language: Haskell 98 -- module Error ( -- * Error formatting elementErrStr, -- * Program termination abortWith, abortWithIO, exitSuccess ) where -- hierachical libraries import System.Environment ( getProgName) import System.Exit ( ExitCode(..), exitWith, exitFailure) -- Produce an error message for a given source, line range, and custom error -- message. -- elementErrStr :: String -> (Int, Int) -> String -> String elementErrStr sname (start, end) err = sname ++ ":" ++ show start ++ "-" ++ show end ++": " ++ err -- Terminate with a set of errors (in pure code). -- abortWith :: [String] -> a abortWith = error . ("FATAL ERROR" ++) . concat . map ('\n':) -- Terminate with a set of errors (in IO code). -- abortWithIO :: [String] -> IO a abortWithIO errs = do name <- getProgName putStrLn $ name ++ ": FATAL ERROR" putStr (unlines errs) exitFailure -- Terminate sucessfully. -- exitSuccess :: IO a exitSuccess = exitWith ExitSuccess