haskell-hvr / cassava

A CSV parsing and encoding library optimized for ease of use and high performance
http://hackage.haskell.org/package/cassava
BSD 3-Clause "New" or "Revised" License
222 stars 105 forks source link

improve error messages for `lookup` #197

Closed kuribas closed 2 years ago

kuribas commented 3 years ago

Error messages in genericParseNamedRecord don't mention in which field the error occurs:

λ> data Person = Person { name :: !String , salary :: !Int } deriving (Generic, Show) λ> instance ToNamedRecord Person λ> instance FromNamedRecord Person λ> (runParser $ parseNamedRecord $ fromList [("name","Kristof"),("salary","foobar"),("foo", "32")]) :: Either String Person Left "expected Int, got \"foobar\" (Failed reading: takeWhile1)"

This pull request changes the error message to:

Left "in named field \"salary\": expected Int, got \"foobar\" (Failed reading: takeWhile1)"

kuribas commented 3 years ago

any update?

dminuoso commented 2 years ago

This would be nice to have.

andreasabel commented 2 years ago

Thanks @kuribas , for the PR! Could you rebase it on latest master so that CI can run on it? Would it be possible to add a test demonstrating the new behavior in a reproducible way?