mirror of
https://git.nerfingen.de/nerf/choirMail.git
synced 2025-05-15 17:50:31 +00:00
some error handling and cleanup that comes with it
This commit is contained in:
parent
99ab66b419
commit
616fc48990
7 changed files with 91 additions and 31 deletions
|
@ -4,6 +4,7 @@ module Config where
|
|||
import qualified Toml
|
||||
import Toml(TomlCodec, (.=))
|
||||
import qualified Data.Text as T
|
||||
import Monad
|
||||
|
||||
data Config = Config {
|
||||
mailDomain :: String
|
||||
|
@ -11,6 +12,7 @@ data Config = Config {
|
|||
,mailPassword :: String
|
||||
,mailTo :: T.Text
|
||||
,mailFrom :: T.Text
|
||||
,mailErrorTo :: T.Text
|
||||
} deriving Show
|
||||
|
||||
configCodec :: TomlCodec Config
|
||||
|
@ -20,10 +22,11 @@ configCodec = Config
|
|||
<*> Toml.string "mailPassword" .= mailPassword
|
||||
<*> Toml.text "mailTo" .= mailTo
|
||||
<*> Toml.text "mailFrom" .= mailFrom
|
||||
<*> Toml.text "mailErrorTo" .= mailErrorTo
|
||||
|
||||
parseFile :: String -> IO (Either String Config)
|
||||
parseFile path = do
|
||||
config <- Toml.decodeFileEither configCodec path
|
||||
parseConfigFile :: (MonadIO m, MonadFail m) => String -> m Config
|
||||
parseConfigFile path = do
|
||||
config <- liftIO $ Toml.decodeFileEither configCodec path
|
||||
case config of
|
||||
Left errors -> return $ Left $ unwords $ fmap show errors
|
||||
Right x -> return $ Right $ x
|
||||
Left errors -> fail $ unwords $ fmap show errors
|
||||
Right x -> return x
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue