Skip to content

Commit da2e0b1

Browse files
author
Chris Cornwell
committed
include index of failure in error message when decoding array
1 parent 9c75838 commit da2e0b1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Data/Argonaut/Decode/Class.purs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Data.Map as M
1414
import Data.Maybe (maybe, Maybe(..))
1515
import Data.String (CodePoint, codePointAt)
1616
import Data.Traversable (traverse)
17+
import Data.TraversableWithIndex (traverseWithIndex)
1718
import Data.Tuple (Tuple(..))
1819
import Foreign.Object as FO
1920

@@ -75,8 +76,11 @@ instance decodeForeignObject :: DecodeJson a => DecodeJson (FO.Object a) where
7576

7677
instance decodeArray :: DecodeJson a => DecodeJson (Array a) where
7778
decodeJson
78-
= lmap ("Couldn't decode Array: " <> _)
79-
<<< (traverse decodeJson <=< decodeJArray)
79+
= lmap ("Couldn't decode Array (" <> _)
80+
<<< (traverseWithIndex f <=< decodeJArray)
81+
where
82+
msg i m = "Failed at index " <> show i <> "): " <> m
83+
f i = lmap (msg i) <<< decodeJson
8084

8185
instance decodeList :: DecodeJson a => DecodeJson (List a) where
8286
decodeJson

0 commit comments

Comments
 (0)