Skip to content

Commit

Permalink
Merge pull request #197 from kuribas/master
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasabel authored Nov 16, 2021
2 parents 792cf58 + 43eaa6b commit 5a410c9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Version 0.5.3.0

* improve error messages for `lookup` and NamedRecord parsers.

## Version 0.5.2.0

* Add `FromField`/`ToField` instances for `Identity` and `Const` (#158)
Expand Down
2 changes: 1 addition & 1 deletion cassava.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 1.12
Name: cassava
Version: 0.5.2.0
Version: 0.5.3.0
Synopsis: A CSV parsing and encoding library
Description: {

Expand Down
5 changes: 4 additions & 1 deletion src/Data/Csv/Conversion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,8 +1148,11 @@ unsafeIndex v idx = parseField (V.unsafeIndex v idx)
-- 'empty' if the field is missing or if the value cannot be converted
-- to the desired type.
lookup :: FromField a => NamedRecord -> B.ByteString -> Parser a
lookup m name = maybe (fail err) parseField $ HM.lookup name m
lookup m name = maybe (fail err) parseField' $ HM.lookup name m
where err = "no field named " ++ show (B8.unpack name)
parseField' fld = case runParser (parseField fld) of
Left e -> fail $ "in named field " ++ show (B8.unpack name) ++ ": " ++ e
Right res -> pure res
{-# INLINE lookup #-}

-- | Alias for 'lookup'.
Expand Down

0 comments on commit 5a410c9

Please sign in to comment.