on master help sign in
Fix some warnings
e645c63Michael Snoyman
Data/Yaml/Config.hs+4−1
@@ -93,7 +93,10 @@ applyEnvValue requireEnv' env =
93 _ -> Null
93 _ -> Null
94 goV v = v
94 goV v = v
95
95
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)
97
100
98-- | Get the actual environment as a @HashMap@ from @Text@ to @Text@.
101-- | Get the actual environment as a @HashMap@ from @Text@ to @Text@.
99--
102--
Data/Yaml/TH.hs+5−11
@@ -30,7 +30,6 @@ import Language.Haskell.TH.Quote
30
30
31import Data.Yaml hiding (decodeFile)
31import Data.Yaml hiding (decodeFile)
32
32
33−#if MIN_VERSION_template_haskell(2,9,0)
34-- | Decode a YAML file at compile time. Only available on GHC version @7.8.1@
33-- | Decode a YAML file at compile time. Only available on GHC version @7.8.1@
35-- or higher.
34-- or higher.
36--
35--
@@ -47,18 +46,13 @@ import Data.Yaml hiding (decodeFile)
47decodeFile :: forall a. (Lift a, FromJSON a) => FilePath -> Q (TExp a)
46decodeFile :: forall a. (Lift a, FromJSON a) => FilePath -> Q (TExp a)
48decodeFile path = do
47decodeFile path = do
49 addDependentFile path
48 addDependentFile path
50− runIO (decodeFileEither path) >>= \case
49+ x <- runIO $ decodeFileThrow path
51− Left err -> fail (prettyPrintParseException err)
52− Right x -> fmap TExp (lift (x :: a))
50+ fmap TExp (lift (x :: a))
53−#endif
54−
55−decodeValue :: String -> Either String Value
56−decodeValue = decodeEither . encodeUtf8 . T.pack
57
51
58yamlExp :: String -> Q Exp
52yamlExp :: String -> Q Exp
59−yamlExp input = case decodeValue input of
53+yamlExp input = do
60− Left err -> fail err
54+ val <- runIO $ decodeThrow $ encodeUtf8 $ T.pack input
61− Right a -> lift a
55+ lift (val :: Value)
62
56
63-- | A @QuasiQuoter@ for YAML.
57-- | A @QuasiQuoter@ for YAML.
64--
58--
appveyor.yml+1−1
@@ -29,4 +29,4 @@ test_script:
29
29
30# The ugly echo "" hack is to avoid complaints about 0 being an invalid file
30# The ugly echo "" hack is to avoid complaints about 0 being an invalid file
31# descriptor
31# 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
50 parseJSON _ = fail "Expected Object for Config value"
50 parseJSON _ = fail "Expected Object for Config value"
51
51
52main :: IO ()
52main :: IO ()
53−main =
53+main = do
54− print $ (Y.decode configYaml :: Maybe Config)
54+ config <- Y.decodeThrow configYaml
55+ print (config :: Config)
examples/Simple.hs+2−1
@@ -6,7 +6,8 @@ import qualified Data.Yaml as Y
6
6
7main :: IO ()
7main :: IO ()
8main = do
8main = do
9− print $ (Y.decode "[1,2,3]" :: Maybe [Integer])
9+ res <- Y.decodeThrow "[1,2,3]"
10+ print (res :: [Integer])
10
11
11-- You can go one step further and decode into a custom type by implementing
12-- You can go one step further and decode into a custom type by implementing
12-- 'FromJSON' for that type. This is also appropriate where extra
13-- 'FromJSON' for that type. This is also appropriate where extra