on master help sign in
make the key show up in the error message
commitf6006393a663dd1dc391aabf304ef3181fbdead5 authorGreg Weber <greg@gregweber.info> dateSun 23 Aug 2015, 17:41 (11 years ago) parent44212b4
1 file changed+8−2
Data/Aeson/Types/Instances.hs+8−2
Data/Aeson/Types/Instances.hs+8−2
@@ -1527,7 +1527,10 @@ ifromJSON = iparse parseJSON
15271527(.:) :: (FromJSON a) => Object -> Text -> Parser a
15281528obj .: key = case H.lookup key obj of
15291529 Nothing -> fail $ "key " ++ show key ++ " not present"
1530− Just v -> parseJSON v <?> Key key
1530+ Just v -> modifyFailure addKeyName
1531+ $ parseJSON v <?> Key key
1532+ where
1533+ addKeyName = (("failed to parse field " <> unpack key <> ": ") <>)
15311534{-# INLINE (.:) #-}
15321535
15331536-- | Retrieve the value associated with the given key of an 'Object'.
@@ -1540,7 +1543,10 @@ obj .: key = case H.lookup key obj of
15401543(.:?) :: (FromJSON a) => Object -> Text -> Parser (Maybe a)
15411544obj .:? key = case H.lookup key obj of
15421545 Nothing -> pure Nothing
1543− Just v -> Just <$> parseJSON v <?> Key key
1546+ Just v -> modifyFailure addKeyName
1547+ $ Just <$> parseJSON v <?> Key key
1548+ where
1549+ addKeyName = (("failed to parse field " <> unpack key <> ": ") <>)
15441550{-# INLINE (.:?) #-}
15451551
15461552-- | Helper for use in combination with '.:?' to provide default