@@ -14,7 +14,7 @@ import Data.Argonaut.Core (Json(), foldJsonNull, foldJsonBoolean, foldJsonNumber
1414import Data.Array (zipWithA )
1515import Data.Either (either , Either (..))
1616import Data.Foldable (find )
17- import Data.Generic (Generic , GenericSpine (..), GenericSignature (..), Proxy (..), fromSpine , toSignature )
17+ import Data.Generic (Generic , GenericSpine (..), GenericSignature (..), fromSpine , toSignature )
1818import Data.Int (fromNumber )
1919import Data.List (List (..), toList )
2020import Data.Map as Map
@@ -23,6 +23,7 @@ import Data.String (charAt, toChar)
2323import Data.StrMap as M
2424import Data.Traversable (traverse , for )
2525import Data.Tuple (Tuple (..))
26+ import Type.Proxy (Proxy (..))
2627
2728class DecodeJson a where
2829 decodeJson :: Json -> Either String a
@@ -49,9 +50,10 @@ gDecodeJson' signature json = case signature of
4950 pf <- mFail (" '" <> lbl <> " ' property missing" ) (M .lookup lbl jObj)
5051 sp <- gDecodeJson' (val unit) pf
5152 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)
5557 case find ((tag ==) <<< _.sigConstructor) alts of
5658 Nothing -> Left (" '" <> tag <> " ' isn't a valid constructor" )
5759 Just { sigValues: sigValues } -> do
0 commit comments