Skip to content

Commit 7bcf368

Browse files
committed
Accumulate NonEmpty errors
1 parent 9eef7e7 commit 7bcf368

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Data/Aeson/Types/FromJSON.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ parseVersionText = go . readP_to_S parseVersion . unpack
14141414

14151415
instance FromJSON1 NonEmpty where
14161416
liftParseJSON p _ = withArray "NonEmpty a" $
1417-
(>>= ne) . Tr.sequence . zipWith (parseIndexedJSON p) [0..] . V.toList
1417+
(>>= ne) . accSequence . zipWith (parseIndexedJSON p) [0..] . V.toList
14181418
where
14191419
ne [] = fail "Expected a NonEmpty but got an empty list"
14201420
ne (x:xs) = pure (x :| xs)

tests/UnitTests/AccErrors.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import qualified Data.Sequence as Seq
2121

2222
tests :: Test
2323
tests = testGroup "Error accumulation" [
24-
testCase "seq" seq
25-
, testCase "vector" vector
24+
testCase "Seq" seq
25+
, testCase "Vector" vector
26+
, testCase "NonEmpty" nonEmpty
2627
]
2728

2829
decoder :: FromJSON a
@@ -41,3 +42,9 @@ vector = do
4142
let res = decoder "[true, null]" :: Either (NonEmpty (JSONPath, String)) (Vector Int)
4243
let message i s = ([Index i], "expected Int, encountered " <> s)
4344
res @=? Left (NL.fromList [message 0 "Boolean", message 1 "Null"])
45+
46+
nonEmpty :: Assertion
47+
nonEmpty = do
48+
let res = decoder "[true, null]" :: Either (NonEmpty (JSONPath, String)) (NL.NonEmpty Int)
49+
let message i s = ([Index i], "expected Int, encountered " <> s)
50+
res @=? Left (NL.fromList [message 0 "Boolean", message 1 "Null"])

0 commit comments

Comments
 (0)