Skip to content

Commit 5a410c9

Browse files
authored
Merge pull request #197 from kuribas/master
2 parents 792cf58 + 43eaa6b commit 5a410c9

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Version 0.5.3.0
2+
3+
* improve error messages for `lookup` and NamedRecord parsers.
4+
15
## Version 0.5.2.0
26

37
* Add `FromField`/`ToField` instances for `Identity` and `Const` (#158)

cassava.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 1.12
22
Name: cassava
3-
Version: 0.5.2.0
3+
Version: 0.5.3.0
44
Synopsis: A CSV parsing and encoding library
55
Description: {
66

src/Data/Csv/Conversion.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,8 +1148,11 @@ unsafeIndex v idx = parseField (V.unsafeIndex v idx)
11481148
-- 'empty' if the field is missing or if the value cannot be converted
11491149
-- to the desired type.
11501150
lookup :: FromField a => NamedRecord -> B.ByteString -> Parser a
1151-
lookup m name = maybe (fail err) parseField $ HM.lookup name m
1151+
lookup m name = maybe (fail err) parseField' $ HM.lookup name m
11521152
where err = "no field named " ++ show (B8.unpack name)
1153+
parseField' fld = case runParser (parseField fld) of
1154+
Left e -> fail $ "in named field " ++ show (B8.unpack name) ++ ": " ++ e
1155+
Right res -> pure res
11531156
{-# INLINE lookup #-}
11541157

11551158
-- | Alias for 'lookup'.

0 commit comments

Comments
 (0)