mirror of
https://github.com/swarm-game/swarm.git
synced 2024-09-11 22:58:21 +03:00
Fix FromJSON instance for better error msgs (#1882)
Before: ``` ghci> let s = "[{ \"radius\": 2, \"density\": \"x\"}]" ghci> eitherDecodeStrict s :: Either String GrowthSpread Left "Error in $: parsing Growth failed, expected Object, but encountered Array ``` The error msg above is misleading because we weren't trying to parse `Growth` datatype but `GrowthSpread` instead. After: ``` ghci> let s = "[{ \"radius\": 2, \"density\": \"x\"}]" ghci> eitherDecodeStrict s :: Either String GrowthSpread Left "Error in $: parsing GrowthSpread failed, expected Object, but encountered Array" ```
This commit is contained in:
parent
5a034b5939
commit
4a6f413c34
@ -192,7 +192,7 @@ data GrowthSpread = GrowthSpread
|
||||
deriving (Eq, Ord, Show, Read, Generic, Hashable, ToJSON)
|
||||
|
||||
instance FromJSON GrowthSpread where
|
||||
parseJSON = withObject "Growth" $ \v -> do
|
||||
parseJSON = withObject "GrowthSpread" $ \v -> do
|
||||
spreadRadius <- v .: "radius"
|
||||
spreadDensity <- v .: "density"
|
||||
pure GrowthSpread {..}
|
||||
|
Loading…
Reference in New Issue
Block a user