on master help sign in
Fix some warnings
commite645c637e039f286fea4b059aa3e99ec3d0e0e72 authorMichael Snoyman <michael@snoyman.com> dateThu 28 Jun 2018, 16:02 (8 years ago) parenta27dc9d
5 files changed+15−16
Data/Yaml/Config.hs+4−1 Data/Yaml/TH.hs+5−11 appveyor.yml+1−1 examples/Config.hs+3−2 examples/Simple.hs+2−1
Data/Yaml/Config.hs+4−1
@@ -93,7 +93,10 @@ applyEnvValue requireEnv' env =
9393 _ -> Null
9494 goV v = v
9595
96− parseValue val = fromMaybe (String val) $ Y.decode $ encodeUtf8 val
96+ parseValue val = either
97+ (const (String val))
98+ id
99+ (Y.decodeThrow $ encodeUtf8 val)
97100
98101-- | Get the actual environment as a @HashMap@ from @Text@ to @Text@.
99102--
Data/Yaml/TH.hs+5−11
@@ -30,7 +30,6 @@ import Language.Haskell.TH.Quote
3030
3131import Data.Yaml hiding (decodeFile)
3232
33−#if MIN_VERSION_template_haskell(2,9,0)
3433-- | Decode a YAML file at compile time. Only available on GHC version @7.8.1@
3534-- or higher.
3635--
@@ -47,18 +46,13 @@ import Data.Yaml hiding (decodeFile)
4746decodeFile :: forall a. (Lift a, FromJSON a) => FilePath -> Q (TExp a)
4847decodeFile path = do
4948 addDependentFile path
50− runIO (decodeFileEither path) >>= \case
51− Left err -> fail (prettyPrintParseException err)
52− Right x -> fmap TExp (lift (x :: a))
53−#endif
54−
55−decodeValue :: String -> Either String Value
56−decodeValue = decodeEither . encodeUtf8 . T.pack
49+ x <- runIO $ decodeFileThrow path
50+ fmap TExp (lift (x :: a))
5751
5852yamlExp :: String -> Q Exp
59−yamlExp input = case decodeValue input of
60− Left err -> fail err
61− Right a -> lift a
53+yamlExp input = do
54+ val <- runIO $ decodeThrow $ encodeUtf8 $ T.pack input
55+ lift (val :: Value)
6256
6357-- | A @QuasiQuoter@ for YAML.
6458--
appveyor.yml+1−1
@@ -29,4 +29,4 @@ test_script:
2929
3030# The ugly echo "" hack is to avoid complaints about 0 being an invalid file
3131# descriptor
32−- echo "" | stack %ARGS% --no-terminal test --pedantic
32+- echo "" | stack %ARGS% --no-terminal test
examples/Config.hs+3−2
@@ -50,5 +50,6 @@ instance FromJSON Config where
5050 parseJSON _ = fail "Expected Object for Config value"
5151
5252main :: IO ()
53−main =
54− print $ (Y.decode configYaml :: Maybe Config)
53+main = do
54+ config <- Y.decodeThrow configYaml
55+ print (config :: Config)
examples/Simple.hs+2−1
@@ -6,7 +6,8 @@ import qualified Data.Yaml as Y
66
77main :: IO ()
88main = do
9− print $ (Y.decode "[1,2,3]" :: Maybe [Integer])
9+ res <- Y.decodeThrow "[1,2,3]"
10+ print (res :: [Integer])
1011
1112-- You can go one step further and decode into a custom type by implementing
1213-- 'FromJSON' for that type. This is also appropriate where extra