aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFélix Sipma <felix.sipma@no-log.org>2016-05-12 12:50:49 +0200
committerFélix Sipma <felix.sipma@no-log.org>2016-05-12 12:50:49 +0200
commit21147fe579e4173ece624e814d250eab740c87fb (patch)
tree8c1ed6aeed4bc1d29ec5d3341c47fcc13e63c6e5
parent2ee927e6763cf6b1de5f62f7c5040a300c99b44e (diff)
add ParseConfigError
-rw-r--r--src/Config/FileConfig.hs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Config/FileConfig.hs b/src/Config/FileConfig.hs
index ff04951..c75d02d 100644
--- a/src/Config/FileConfig.hs
+++ b/src/Config/FileConfig.hs
@@ -4,6 +4,7 @@ module Config.FileConfig
, writeInternalConfig
) where
+import Control.Exception (throwIO, Exception)
import qualified Data.Yaml as Y
import qualified Data.ByteString.Char8 as BS
import Data.Aeson
@@ -32,6 +33,13 @@ instance FromJSON FileConfig where
parseJSON _ = mzero
+data ParseConfigError = ParseConfigError FilePath
+
+instance Show ParseConfigError where
+ show (ParseConfigError fp) = "ParseConfigError: Could not parse config file \"" ++ fp ++ "\""
+
+instance Exception ParseConfigError
+
instance ToJSON FileConfig where
toJSON (FileConfig mdb minfos mafrom mato mtlength) = object (jdb ++ jinfos ++ jafrom ++ jato ++ jtlength)
where
@@ -51,7 +59,7 @@ parseConfigFile' :: Path Abs File -> IO FileConfig
parseConfigFile' config = do
content <- BS.readFile fpConfig
case (Y.decode content :: Maybe FileConfig) of
- Nothing -> error $ "Could not parse config file \"" ++ fpConfig ++ "\""
+ Nothing -> throwIO (ParseConfigError fpConfig)
Just c -> return c
where
fpConfig = toFilePath config