diff options
-rw-r--r-- | src/Exit.hs | 23 | ||||
-rw-r--r-- | src/Main.hs | 6 | ||||
-rw-r--r-- | src/RenderError.hs | 34 |
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 - ] |