File tree Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -319,7 +319,7 @@ parseNoFields encoding json expectedTag =
319
319
EncodeNested {} → do
320
320
obj ← lmap JErr $ CA .decode jobject json
321
321
val ←
322
- ( Obj .lookup expectedTag obj # note ( JErr $ TypeMismatch ( " Expecting a property ` " <> expectedTag <> " ` " ))
322
+ ( Obj .lookup expectedTag obj # note NoCase
323
323
) ∷ _ Json
324
324
fields ← lmap JErr $ CA .decode CA .jarray val ∷ _ (Array Json )
325
325
when (fields /= [] )
@@ -346,7 +346,7 @@ parseSingleField encoding json expectedTag = case encoding of
346
346
EncodeNested { unwrapSingleArguments } → do
347
347
obj ← lmap JErr $ CA .decode jobject json
348
348
val ←
349
- ( Obj .lookup expectedTag obj # note ( JErr $ TypeMismatch ( " Expecting a property ` " <> expectedTag <> " ` " ))
349
+ ( Obj .lookup expectedTag obj # note NoCase
350
350
) ∷ _ Json
351
351
if unwrapSingleArguments then
352
352
pure val
@@ -472,8 +472,7 @@ instance gFlatCasesConstructorNoArg ∷
472
472
let actualTag = Record .get (Proxy @tag) r ∷ String
473
473
474
474
when (actualTag /= name)
475
- $ Left
476
- (JErr $ TypeMismatch (" Expecting tag `" <> name <> " `, got `" <> actualTag <> " `" ))
475
+ $ Left NoCase
477
476
478
477
pure (Constructor NoArguments )
479
478
@@ -507,8 +506,7 @@ instance gFlatCasesConstructorSingleArg ∷
507
506
508
507
let actualTag = Record .get (Proxy @tag) r ∷ String
509
508
when (actualTag /= name)
510
- $ Left
511
- (JErr $ TypeMismatch (" Expecting tag `" <> name <> " `, got `" <> actualTag <> " `" ))
509
+ $ Left NoCase
512
510
513
511
let r' = Record .delete (Proxy @tag) r ∷ Record rf
514
512
pure (Constructor (Argument r'))
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ module Test.Sum where
3
3
import Prelude
4
4
5
5
import Control.Monad.Error.Class (liftEither )
6
- import Data.Argonaut.Core (stringifyWithIndent )
6
+ import Data.Argonaut.Core (stringify , stringifyWithIndent )
7
7
import Data.Argonaut.Decode (parseJson )
8
8
import Data.Bifunctor (lmap )
9
9
import Data.Codec (decode , encode )
@@ -87,14 +87,14 @@ check ∷ ∀ a. Show a ⇒ Eq a ⇒ JsonCodec a → a → String → Effect Uni
87
87
check codec val expectEncoded = do
88
88
let encodedStr = stringifyWithIndent 2 $ encode codec val
89
89
when (encodedStr /= expectEncoded) $
90
- throw (" check failed, expected: " <> expectEncoded <> " , got: " <> encodedStr)
90
+ throw (" encode check failed, expected: " <> expectEncoded <> " , got: " <> encodedStr)
91
91
92
92
json ← liftEither $ lmap (show >>> error) $ parseJson encodedStr
93
93
94
- decoded ← liftEither $ lmap (show >>> error ) $ decode codec json
94
+ decoded ← liftEither $ lmap (\err -> error ( " decode failed: " <> show err <> " JSON was: " <> stringify json) ) $ decode codec json
95
95
96
96
when (decoded /= val) $
97
- throw (" check failed, expected: " <> show val <> " , got: " <> show decoded)
97
+ throw (" decode check failed, expected: " <> show val <> " , got: " <> show decoded)
98
98
99
99
main ∷ Effect Unit
100
100
main = do
You can’t perform that action at this time.
0 commit comments