Replace decodeFile with decodeFileEither
This commit is contained in:
parent
5943ee527d
commit
cfaf517f54
@ -179,8 +179,8 @@ loadConfig :: ConfigSettings environment extra
|
|||||||
-> IO (AppConfig environment extra)
|
-> IO (AppConfig environment extra)
|
||||||
loadConfig (ConfigSettings env parseExtra getFile getObject) = do
|
loadConfig (ConfigSettings env parseExtra getFile getObject) = do
|
||||||
fp <- getFile env
|
fp <- getFile env
|
||||||
mtopObj <- decodeFile fp
|
etopObj <- decodeFileEither fp
|
||||||
topObj <- maybe (fail "Invalid YAML file") return mtopObj
|
topObj <- either (const $ fail "Invalid YAML file") return etopObj
|
||||||
obj <- getObject env topObj
|
obj <- getObject env topObj
|
||||||
m <-
|
m <-
|
||||||
case obj of
|
case obj of
|
||||||
@ -232,9 +232,10 @@ withYamlEnvironment :: Show e
|
|||||||
-> (Value -> Parser a) -- ^ what to do with the mapping
|
-> (Value -> Parser a) -- ^ what to do with the mapping
|
||||||
-> IO a
|
-> IO a
|
||||||
withYamlEnvironment fp env f = do
|
withYamlEnvironment fp env f = do
|
||||||
mval <- decodeFile fp
|
mval <- decodeFileEither fp
|
||||||
case mval of
|
case mval of
|
||||||
Nothing -> fail $ "Invalid YAML file: " ++ show fp
|
Left err ->
|
||||||
Just (Object obj)
|
fail $ "Invalid YAML file: " ++ show fp ++ " " ++ prettyPrintParseException err
|
||||||
|
Right (Object obj)
|
||||||
| Just v <- M.lookup (T.pack $ show env) obj -> parseMonad f v
|
| Just v <- M.lookup (T.pack $ show env) obj -> parseMonad f v
|
||||||
_ -> fail $ "Could not find environment: " ++ show env
|
_ -> fail $ "Could not find environment: " ++ show env
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user