@@ -49,6 +49,7 @@ module Data.Yaml
49 , decodeFile
49 , decodeFile
50 -- ** Better error information
50 -- ** Better error information
51 , decodeEither
51 , decodeEither
52 -- ** More control over decoding
53 -- ** More control over decoding
53 , decodeHelper
54 , decodeHelper
@@ -138,6 +139,7 @@ data ParseException = NonScalarKey
138 , _expected :: Maybe Event
139 , _expected :: Maybe Event
140 | InvalidYaml (Maybe YamlException)
141 | InvalidYaml (Maybe YamlException)
142+ | AesonException String
141 deriving (Show, Typeable)
143 deriving (Show, Typeable)
142instance Exception ParseException
144instance Exception ParseException
@@ -279,6 +281,15 @@ decodeEither bs = unsafePerformIO
279 $ fmap (either (Left . show) id)
281 $ fmap (either (Left . show) id)
280 $ decodeHelper (Y.decode bs)
282 $ decodeHelper (Y.decode bs)
284+-- | More helpful version of 'decodeEither' which returns the 'YamlException'.
287+decodeEither' :: FromJSON a => ByteString -> Either ParseException a
288+decodeEither' = either Left (either (Left . AesonException) Right)
282decodeHelper :: FromJSON a
293decodeHelper :: FromJSON a
283 => C.Source Parse Y.Event
294 => C.Source Parse Y.Event
284 -> IO (Either ParseException (Either String a))
295 -> IO (Either ParseException (Either String a))