@@ -14,7 +14,7 @@ import Data.Argonaut.Core (Json(), foldJsonNull, foldJsonBoolean, foldJsonNumber
14
14
import Data.Array (zipWithA )
15
15
import Data.Either (either , Either (..))
16
16
import Data.Foldable (find )
17
- import Data.Generic (Generic , GenericSpine (..), GenericSignature (..), Proxy (..), fromSpine , toSignature )
17
+ import Data.Generic (Generic , GenericSpine (..), GenericSignature (..), fromSpine , toSignature )
18
18
import Data.Int (fromNumber )
19
19
import Data.List (List (..), toList )
20
20
import Data.Map as Map
@@ -23,6 +23,7 @@ import Data.String (charAt, toChar)
23
23
import Data.StrMap as M
24
24
import Data.Traversable (traverse , for )
25
25
import Data.Tuple (Tuple (..))
26
+ import Type.Proxy (Proxy (..))
26
27
27
28
class DecodeJson a where
28
29
decodeJson :: Json -> Either String a
@@ -49,9 +50,10 @@ gDecodeJson' signature json = case signature of
49
50
pf <- mFail (" '" <> lbl <> " ' property missing" ) (M .lookup lbl jObj)
50
51
sp <- gDecodeJson' (val unit) pf
51
52
pure { recLabel: lbl, recValue: const sp }
52
- SigProd alts -> do
53
- jObj <- mFail " Expected an object" $ toObject json
54
- tag <- mFail " 'tag' string property is missing" (toString =<< M .lookup " tag" jObj)
53
+ SigProd typeConstr alts -> do
54
+ let decodingErr msg = " When decoding " ++ typeConstr ++ " " ++ msg
55
+ jObj <- mFail (decodingErr " expected an object" ) (toObject json)
56
+ tag <- mFail (decodingErr " 'tag' string property is missing" ) (toString =<< M .lookup " tag" jObj)
55
57
case find ((tag ==) <<< _.sigConstructor) alts of
56
58
Nothing -> Left (" '" <> tag <> " ' isn't a valid constructor" )
57
59
Just { sigValues: sigValues } -> do
0 commit comments