@@ -49,6 +49,7 @@ module Data.Yaml
4949 , decodeFile
5050 -- ** Better error information
5151 , decodeEither
52+ , decodeEither'
5253 -- ** More control over decoding
5354 , decodeHelper
5455 ) where
@@ -138,6 +139,7 @@ data ParseException = NonScalarKey
138139 , _expected :: Maybe Event
139140 }
140141 | InvalidYaml (Maybe YamlException)
142+ | AesonException String
141143 deriving (Show, Typeable)
142144instance Exception ParseException
143145
@@ -279,6 +281,15 @@ decodeEither bs = unsafePerformIO
279281 $ fmap (either (Left . show) id)
280282 $ decodeHelper (Y.decode bs)
281283
284+-- | More helpful version of 'decodeEither' which returns the 'YamlException'.
285+--
286+-- Since 0.8.3
287+decodeEither' :: FromJSON a => ByteString -> Either ParseException a
288+decodeEither' = either Left (either (Left . AesonException) Right)
289+ . unsafePerformIO
290+ . decodeHelper
291+ . Y.decode
292+
282293decodeHelper :: FromJSON a
283294 => C.Source Parse Y.Event
284295 -> IO (Either ParseException (Either String a))