aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoris2015-11-22 20:36:59 +0100
committerJoris2015-11-22 20:36:59 +0100
commita9bc46efe3624344573f96fafa8af194016183a2 (patch)
treea863a2c9029620b06ea617a4caaba1c621150949 /src
parent3abc150dc92171129f3b8209e57f6d5bdadf5c9b (diff)
Exit failure when there are parsing errors
Diffstat (limited to 'src')
-rw-r--r--src/Exit.hs23
-rw-r--r--src/Main.hs6
-rw-r--r--src/RenderError.hs34
3 files changed, 26 insertions, 37 deletions
diff --git a/src/Exit.hs b/src/Exit.hs
new file mode 100644
index 0000000..1a08931
--- /dev/null
+++ b/src/Exit.hs
@@ -0,0 +1,23 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Exit
+ ( exitWithParsingError
+ ) where
+
+import System.IO (stderr)
+import System.Exit (exitFailure)
+
+import Data.Text (Text)
+import qualified Data.Text as T
+import qualified Data.Text.IO as T
+
+exitWithParsingError :: FilePath -> Text -> IO ()
+exitWithParsingError path err = do
+ T.hPutStr stderr $
+ T.concat
+ [ "Error while parsing file "
+ , T.pack path
+ , ":\n"
+ , err
+ ]
+ exitFailure
diff --git a/src/Main.hs b/src/Main.hs
index a9d5731..3a34269 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -6,7 +6,7 @@ module Main
import qualified Data.Text.IO as T
-import qualified RenderError
+import Exit (exitWithParsingError)
import Notification (notifyTodayAndNextWeek)
import Model.Config
@@ -18,6 +18,6 @@ main = do
eitherBirthdates <- parseBirthdates <$> T.readFile Path.birthdate
eitherConfig <- getConfig Path.config
case (eitherBirthdates, eitherConfig) of
- (Left err, _) -> RenderError.birthdate err
- (_, Left err) -> RenderError.config err
+ (Left err, _) -> exitWithParsingError Path.birthdate err
+ (_, Left err) -> exitWithParsingError Path.config err
(Right birthdates, Right config) -> notifyTodayAndNextWeek birthdates config
diff --git a/src/RenderError.hs b/src/RenderError.hs
deleted file mode 100644
index 9b9732f..0000000
--- a/src/RenderError.hs
+++ /dev/null
@@ -1,34 +0,0 @@
-{-# LANGUAGE OverloadedStrings #-}
-
-module RenderError
- ( birthdate
- , config
- ) where
-
-import System.IO (stderr)
-
-import Data.Text (Text)
-import qualified Data.Text as T
-import qualified Data.Text.IO as T
-
-import qualified Model.Path as Path
-
-birthdate :: Text -> IO ()
-birthdate err =
- T.hPutStr stderr $
- T.concat
- [ "Error while parsing file "
- , T.pack Path.birthdate
- , ":\n"
- , err
- ]
-
-config :: Text -> IO ()
-config err =
- T.hPutStr stderr $
- T.concat
- [ "Error while parsing config file "
- , T.pack Path.config
- , ":\n"
- , err
- ]