{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE UndecidableInstances #-}
module Jordan.Types.JSONError where
import Control.DeepSeq
import Data.Coerce
import Data.Foldable
import Data.Functor.Contravariant
import qualified Data.List.NonEmpty as NE
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import Data.Text (Text, pack)
import qualified Data.Text.Lazy.Builder as LB
import GHC.Exts (IsList (..))
import GHC.Generics
import Jordan.FromJSON.Class
import Jordan.ToJSON.Class
import Jordan.Types.Internal.MergeMap
import Jordan.Types.JSONType
data JSONError
=
ErrorMesage Text
|
ErrorInvalidJSON
|
ErrorBadType {JSONError -> JSONType
expectedType :: !JSONType, JSONError -> JSONType
actualType :: !JSONType}
|
ErrorNoValue
|
ErrorBadTextConstant {JSONError -> Text
expectedText :: !Text, JSONError -> Text
actualText :: !Text}
|
ErrorBadObject JSONObjectError
|
ErrorBadArray JSONArrayError
|
ErrorChoice !(Set.Set JSONError)
deriving (Int -> JSONError -> ShowS
[JSONError] -> ShowS
JSONError -> String
(Int -> JSONError -> ShowS)
-> (JSONError -> String)
-> ([JSONError] -> ShowS)
-> Show JSONError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [JSONError] -> ShowS
$cshowList :: [JSONError] -> ShowS
show :: JSONError -> String
$cshow :: JSONError -> String
showsPrec :: Int -> JSONError -> ShowS
$cshowsPrec :: Int -> JSONError -> ShowS
Show, JSONError -> JSONError -> Bool
(JSONError -> JSONError -> Bool)
-> (JSONError -> JSONError -> Bool) -> Eq JSONError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: JSONError -> JSONError -> Bool
$c/= :: JSONError -> JSONError -> Bool
== :: JSONError -> JSONError -> Bool
$c== :: JSONError -> JSONError -> Bool
Eq, ReadPrec [JSONError]
ReadPrec JSONError
Int -> ReadS JSONError
ReadS [JSONError]
(Int -> ReadS JSONError)
-> ReadS [JSONError]
-> ReadPrec JSONError
-> ReadPrec [JSONError]
-> Read JSONError
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [JSONError]
$creadListPrec :: ReadPrec [JSONError]
readPrec :: ReadPrec JSONError
$creadPrec :: ReadPrec JSONError
readList :: ReadS [JSONError]
$creadList :: ReadS [JSONError]
readsPrec :: Int -> ReadS JSONError
$creadsPrec :: Int -> ReadS JSONError
Read, Eq JSONError
Eq JSONError
-> (JSONError -> JSONError -> Ordering)
-> (JSONError -> JSONError -> Bool)
-> (JSONError -> JSONError -> Bool)
-> (JSONError -> JSONError -> Bool)
-> (JSONError -> JSONError -> Bool)
-> (JSONError -> JSONError -> JSONError)
-> (JSONError -> JSONError -> JSONError)
-> Ord JSONError
JSONError -> JSONError -> Bool
JSONError -> JSONError -> Ordering
JSONError -> JSONError -> JSONError
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: JSONError -> JSONError -> JSONError
$cmin :: JSONError -> JSONError -> JSONError
max :: JSONError -> JSONError -> JSONError
$cmax :: JSONError -> JSONError -> JSONError
>= :: JSONError -> JSONError -> Bool
$c>= :: JSONError -> JSONError -> Bool
> :: JSONError -> JSONError -> Bool
$c> :: JSONError -> JSONError -> Bool
<= :: JSONError -> JSONError -> Bool
$c<= :: JSONError -> JSONError -> Bool
< :: JSONError -> JSONError -> Bool
$c< :: JSONError -> JSONError -> Bool
compare :: JSONError -> JSONError -> Ordering
$ccompare :: JSONError -> JSONError -> Ordering
$cp1Ord :: Eq JSONError
Ord, (forall x. JSONError -> Rep JSONError x)
-> (forall x. Rep JSONError x -> JSONError) -> Generic JSONError
forall x. Rep JSONError x -> JSONError
forall x. JSONError -> Rep JSONError x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep JSONError x -> JSONError
$cfrom :: forall x. JSONError -> Rep JSONError x
Generic)
deriving anyclass ((forall (f :: * -> *). JSONSerializer f => f JSONError)
-> ToJSON JSONError
forall v.
(forall (f :: * -> *). JSONSerializer f => f v) -> ToJSON v
forall (f :: * -> *). JSONSerializer f => f JSONError
toJSON :: f JSONError
$ctoJSON :: forall (f :: * -> *). JSONSerializer f => f JSONError
ToJSON, (forall (f :: * -> *). JSONParser f => f JSONError)
-> FromJSON JSONError
forall value.
(forall (f :: * -> *). JSONParser f => f value) -> FromJSON value
forall (f :: * -> *). JSONParser f => f JSONError
fromJSON :: f JSONError
$cfromJSON :: forall (f :: * -> *). JSONParser f => f JSONError
FromJSON)
instance Semigroup JSONError where
<> :: JSONError -> JSONError -> JSONError
(<>) JSONError
ErrorNoValue JSONError
ErrorNoValue = JSONError
ErrorNoValue
(<>) JSONError
ErrorNoValue !JSONError
a = JSONError
a
(<>) !JSONError
a JSONError
ErrorNoValue = JSONError
a
(<>) (ErrorChoice Set JSONError
lhs) (ErrorChoice Set JSONError
rhs) = Set JSONError -> JSONError
ErrorChoice (Set JSONError -> JSONError) -> Set JSONError -> JSONError
forall a b. (a -> b) -> a -> b
$ Set JSONError
lhs Set JSONError -> Set JSONError -> Set JSONError
forall a. Semigroup a => a -> a -> a
<> Set JSONError
rhs
(<>) (ErrorChoice Set JSONError
a) !JSONError
rhs = Set JSONError -> JSONError
ErrorChoice (Set JSONError -> JSONError) -> Set JSONError -> JSONError
forall a b. (a -> b) -> a -> b
$ Set JSONError
a Set JSONError -> Set JSONError -> Set JSONError
forall a. Semigroup a => a -> a -> a
<> JSONError -> Set JSONError
forall a. a -> Set a
Set.singleton JSONError
rhs
(<>) !JSONError
a (ErrorChoice Set JSONError
rhs) = Set JSONError -> JSONError
ErrorChoice (JSONError -> Set JSONError
forall a. a -> Set a
Set.singleton JSONError
a Set JSONError -> Set JSONError -> Set JSONError
forall a. Semigroup a => a -> a -> a
<> Set JSONError
rhs)
(<>) !JSONError
lhs !JSONError
rhs = Set JSONError -> JSONError
ErrorChoice (JSONError -> Set JSONError
forall a. a -> Set a
Set.singleton JSONError
lhs Set JSONError -> Set JSONError -> Set JSONError
forall a. Semigroup a => a -> a -> a
<> JSONError -> Set JSONError
forall a. a -> Set a
Set.singleton JSONError
rhs)
instance NFData JSONError
instance Monoid JSONError where
mempty :: JSONError
mempty = JSONError
ErrorNoValue
newtype JSONObjectError = MkJSONObjectError (Map.Map Text JSONError)
deriving (JSONObjectError -> JSONObjectError -> Bool
(JSONObjectError -> JSONObjectError -> Bool)
-> (JSONObjectError -> JSONObjectError -> Bool)
-> Eq JSONObjectError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: JSONObjectError -> JSONObjectError -> Bool
$c/= :: JSONObjectError -> JSONObjectError -> Bool
== :: JSONObjectError -> JSONObjectError -> Bool
$c== :: JSONObjectError -> JSONObjectError -> Bool
Eq, Eq JSONObjectError
Eq JSONObjectError
-> (JSONObjectError -> JSONObjectError -> Ordering)
-> (JSONObjectError -> JSONObjectError -> Bool)
-> (JSONObjectError -> JSONObjectError -> Bool)
-> (JSONObjectError -> JSONObjectError -> Bool)
-> (JSONObjectError -> JSONObjectError -> Bool)
-> (JSONObjectError -> JSONObjectError -> JSONObjectError)
-> (JSONObjectError -> JSONObjectError -> JSONObjectError)
-> Ord JSONObjectError
JSONObjectError -> JSONObjectError -> Bool
JSONObjectError -> JSONObjectError -> Ordering
JSONObjectError -> JSONObjectError -> JSONObjectError
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: JSONObjectError -> JSONObjectError -> JSONObjectError
$cmin :: JSONObjectError -> JSONObjectError -> JSONObjectError
max :: JSONObjectError -> JSONObjectError -> JSONObjectError
$cmax :: JSONObjectError -> JSONObjectError -> JSONObjectError
>= :: JSONObjectError -> JSONObjectError -> Bool
$c>= :: JSONObjectError -> JSONObjectError -> Bool
> :: JSONObjectError -> JSONObjectError -> Bool
$c> :: JSONObjectError -> JSONObjectError -> Bool
<= :: JSONObjectError -> JSONObjectError -> Bool
$c<= :: JSONObjectError -> JSONObjectError -> Bool
< :: JSONObjectError -> JSONObjectError -> Bool
$c< :: JSONObjectError -> JSONObjectError -> Bool
compare :: JSONObjectError -> JSONObjectError -> Ordering
$ccompare :: JSONObjectError -> JSONObjectError -> Ordering
$cp1Ord :: Eq JSONObjectError
Ord, (forall x. JSONObjectError -> Rep JSONObjectError x)
-> (forall x. Rep JSONObjectError x -> JSONObjectError)
-> Generic JSONObjectError
forall x. Rep JSONObjectError x -> JSONObjectError
forall x. JSONObjectError -> Rep JSONObjectError x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep JSONObjectError x -> JSONObjectError
$cfrom :: forall x. JSONObjectError -> Rep JSONObjectError x
Generic)
deriving (JSONObjectError -> ()
(JSONObjectError -> ()) -> NFData JSONObjectError
forall a. (a -> ()) -> NFData a
rnf :: JSONObjectError -> ()
$crnf :: JSONObjectError -> ()
NFData, Int -> [Item JSONObjectError] -> JSONObjectError
[Item JSONObjectError] -> JSONObjectError
JSONObjectError -> [Item JSONObjectError]
([Item JSONObjectError] -> JSONObjectError)
-> (Int -> [Item JSONObjectError] -> JSONObjectError)
-> (JSONObjectError -> [Item JSONObjectError])
-> IsList JSONObjectError
forall l.
([Item l] -> l)
-> (Int -> [Item l] -> l) -> (l -> [Item l]) -> IsList l
toList :: JSONObjectError -> [Item JSONObjectError]
$ctoList :: JSONObjectError -> [Item JSONObjectError]
fromListN :: Int -> [Item JSONObjectError] -> JSONObjectError
$cfromListN :: Int -> [Item JSONObjectError] -> JSONObjectError
fromList :: [Item JSONObjectError] -> JSONObjectError
$cfromList :: [Item JSONObjectError] -> JSONObjectError
IsList, Int -> JSONObjectError -> ShowS
[JSONObjectError] -> ShowS
JSONObjectError -> String
(Int -> JSONObjectError -> ShowS)
-> (JSONObjectError -> String)
-> ([JSONObjectError] -> ShowS)
-> Show JSONObjectError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [JSONObjectError] -> ShowS
$cshowList :: [JSONObjectError] -> ShowS
show :: JSONObjectError -> String
$cshow :: JSONObjectError -> String
showsPrec :: Int -> JSONObjectError -> ShowS
$cshowsPrec :: Int -> JSONObjectError -> ShowS
Show, ReadPrec [JSONObjectError]
ReadPrec JSONObjectError
Int -> ReadS JSONObjectError
ReadS [JSONObjectError]
(Int -> ReadS JSONObjectError)
-> ReadS [JSONObjectError]
-> ReadPrec JSONObjectError
-> ReadPrec [JSONObjectError]
-> Read JSONObjectError
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [JSONObjectError]
$creadListPrec :: ReadPrec [JSONObjectError]
readPrec :: ReadPrec JSONObjectError
$creadPrec :: ReadPrec JSONObjectError
readList :: ReadS [JSONObjectError]
$creadList :: ReadS [JSONObjectError]
readsPrec :: Int -> ReadS JSONObjectError
$creadsPrec :: Int -> ReadS JSONObjectError
Read) via (Map.Map Text JSONError)
deriving (b -> JSONObjectError -> JSONObjectError
NonEmpty JSONObjectError -> JSONObjectError
JSONObjectError -> JSONObjectError -> JSONObjectError
(JSONObjectError -> JSONObjectError -> JSONObjectError)
-> (NonEmpty JSONObjectError -> JSONObjectError)
-> (forall b.
Integral b =>
b -> JSONObjectError -> JSONObjectError)
-> Semigroup JSONObjectError
forall b. Integral b => b -> JSONObjectError -> JSONObjectError
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: b -> JSONObjectError -> JSONObjectError
$cstimes :: forall b. Integral b => b -> JSONObjectError -> JSONObjectError
sconcat :: NonEmpty JSONObjectError -> JSONObjectError
$csconcat :: NonEmpty JSONObjectError -> JSONObjectError
<> :: JSONObjectError -> JSONObjectError -> JSONObjectError
$c<> :: JSONObjectError -> JSONObjectError -> JSONObjectError
Semigroup, Semigroup JSONObjectError
JSONObjectError
Semigroup JSONObjectError
-> JSONObjectError
-> (JSONObjectError -> JSONObjectError -> JSONObjectError)
-> ([JSONObjectError] -> JSONObjectError)
-> Monoid JSONObjectError
[JSONObjectError] -> JSONObjectError
JSONObjectError -> JSONObjectError -> JSONObjectError
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [JSONObjectError] -> JSONObjectError
$cmconcat :: [JSONObjectError] -> JSONObjectError
mappend :: JSONObjectError -> JSONObjectError -> JSONObjectError
$cmappend :: JSONObjectError -> JSONObjectError -> JSONObjectError
mempty :: JSONObjectError
$cmempty :: JSONObjectError
$cp1Monoid :: Semigroup JSONObjectError
Monoid) via (MergeMap Text JSONError)
instance FromJSON JSONObjectError where
fromJSON :: f JSONObjectError
fromJSON = Map Text JSONError -> JSONObjectError
MkJSONObjectError (Map Text JSONError -> JSONObjectError)
-> f (Map Text JSONError) -> f JSONObjectError
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (Map Text JSONError)
forall value (f :: * -> *).
(FromJSON value, JSONParser f) =>
f value
fromJSON
instance ToJSON JSONObjectError where
toJSON :: f JSONObjectError
toJSON = (JSONObjectError -> [(Text, JSONError)])
-> f [(Text, JSONError)] -> f JSONObjectError
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap (Map Text JSONError -> [(Text, JSONError)]
forall k a. Map k a -> [(k, a)]
Map.toAscList (Map Text JSONError -> [(Text, JSONError)])
-> (JSONObjectError -> Map Text JSONError)
-> JSONObjectError
-> [(Text, JSONError)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSONObjectError -> Map Text JSONError
keyValueErrors) (f [(Text, JSONError)] -> f JSONObjectError)
-> f [(Text, JSONError)] -> f JSONObjectError
forall a b. (a -> b) -> a -> b
$ (forall (f :: * -> *). JSONSerializer f => f JSONError)
-> f [(Text, JSONError)]
forall (f :: * -> *) (t :: * -> *) a.
(JSONSerializer f, Foldable t) =>
(forall (jsonSerializer :: * -> *).
JSONSerializer jsonSerializer =>
jsonSerializer a)
-> f (t (Text, a))
serializeDictionary forall v (f :: * -> *). (ToJSON v, JSONSerializer f) => f v
forall (f :: * -> *). JSONSerializer f => f JSONError
toJSON
singleObjectError :: Text -> JSONError -> JSONObjectError
singleObjectError :: Text -> JSONError -> JSONObjectError
singleObjectError Text
t = Map Text JSONError -> JSONObjectError
MkJSONObjectError (Map Text JSONError -> JSONObjectError)
-> (JSONError -> Map Text JSONError)
-> JSONError
-> JSONObjectError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> JSONError -> Map Text JSONError
forall k a. k -> a -> Map k a
Map.singleton Text
t
keyValueErrors :: JSONObjectError -> Map.Map Text JSONError
keyValueErrors :: JSONObjectError -> Map Text JSONError
keyValueErrors = JSONObjectError -> Map Text JSONError
coerce
newtype JSONArrayError = MkJSONArrayError (Map.Map Integer JSONError)
deriving (JSONArrayError -> JSONArrayError -> Bool
(JSONArrayError -> JSONArrayError -> Bool)
-> (JSONArrayError -> JSONArrayError -> Bool) -> Eq JSONArrayError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: JSONArrayError -> JSONArrayError -> Bool
$c/= :: JSONArrayError -> JSONArrayError -> Bool
== :: JSONArrayError -> JSONArrayError -> Bool
$c== :: JSONArrayError -> JSONArrayError -> Bool
Eq, Eq JSONArrayError
Eq JSONArrayError
-> (JSONArrayError -> JSONArrayError -> Ordering)
-> (JSONArrayError -> JSONArrayError -> Bool)
-> (JSONArrayError -> JSONArrayError -> Bool)
-> (JSONArrayError -> JSONArrayError -> Bool)
-> (JSONArrayError -> JSONArrayError -> Bool)
-> (JSONArrayError -> JSONArrayError -> JSONArrayError)
-> (JSONArrayError -> JSONArrayError -> JSONArrayError)
-> Ord JSONArrayError
JSONArrayError -> JSONArrayError -> Bool
JSONArrayError -> JSONArrayError -> Ordering
JSONArrayError -> JSONArrayError -> JSONArrayError
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: JSONArrayError -> JSONArrayError -> JSONArrayError
$cmin :: JSONArrayError -> JSONArrayError -> JSONArrayError
max :: JSONArrayError -> JSONArrayError -> JSONArrayError
$cmax :: JSONArrayError -> JSONArrayError -> JSONArrayError
>= :: JSONArrayError -> JSONArrayError -> Bool
$c>= :: JSONArrayError -> JSONArrayError -> Bool
> :: JSONArrayError -> JSONArrayError -> Bool
$c> :: JSONArrayError -> JSONArrayError -> Bool
<= :: JSONArrayError -> JSONArrayError -> Bool
$c<= :: JSONArrayError -> JSONArrayError -> Bool
< :: JSONArrayError -> JSONArrayError -> Bool
$c< :: JSONArrayError -> JSONArrayError -> Bool
compare :: JSONArrayError -> JSONArrayError -> Ordering
$ccompare :: JSONArrayError -> JSONArrayError -> Ordering
$cp1Ord :: Eq JSONArrayError
Ord, (forall x. JSONArrayError -> Rep JSONArrayError x)
-> (forall x. Rep JSONArrayError x -> JSONArrayError)
-> Generic JSONArrayError
forall x. Rep JSONArrayError x -> JSONArrayError
forall x. JSONArrayError -> Rep JSONArrayError x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep JSONArrayError x -> JSONArrayError
$cfrom :: forall x. JSONArrayError -> Rep JSONArrayError x
Generic)
deriving (JSONArrayError -> ()
(JSONArrayError -> ()) -> NFData JSONArrayError
forall a. (a -> ()) -> NFData a
rnf :: JSONArrayError -> ()
$crnf :: JSONArrayError -> ()
NFData, Int -> [Item JSONArrayError] -> JSONArrayError
[Item JSONArrayError] -> JSONArrayError
JSONArrayError -> [Item JSONArrayError]
([Item JSONArrayError] -> JSONArrayError)
-> (Int -> [Item JSONArrayError] -> JSONArrayError)
-> (JSONArrayError -> [Item JSONArrayError])
-> IsList JSONArrayError
forall l.
([Item l] -> l)
-> (Int -> [Item l] -> l) -> (l -> [Item l]) -> IsList l
toList :: JSONArrayError -> [Item JSONArrayError]
$ctoList :: JSONArrayError -> [Item JSONArrayError]
fromListN :: Int -> [Item JSONArrayError] -> JSONArrayError
$cfromListN :: Int -> [Item JSONArrayError] -> JSONArrayError
fromList :: [Item JSONArrayError] -> JSONArrayError
$cfromList :: [Item JSONArrayError] -> JSONArrayError
IsList, Int -> JSONArrayError -> ShowS
[JSONArrayError] -> ShowS
JSONArrayError -> String
(Int -> JSONArrayError -> ShowS)
-> (JSONArrayError -> String)
-> ([JSONArrayError] -> ShowS)
-> Show JSONArrayError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [JSONArrayError] -> ShowS
$cshowList :: [JSONArrayError] -> ShowS
show :: JSONArrayError -> String
$cshow :: JSONArrayError -> String
showsPrec :: Int -> JSONArrayError -> ShowS
$cshowsPrec :: Int -> JSONArrayError -> ShowS
Show, ReadPrec [JSONArrayError]
ReadPrec JSONArrayError
Int -> ReadS JSONArrayError
ReadS [JSONArrayError]
(Int -> ReadS JSONArrayError)
-> ReadS [JSONArrayError]
-> ReadPrec JSONArrayError
-> ReadPrec [JSONArrayError]
-> Read JSONArrayError
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [JSONArrayError]
$creadListPrec :: ReadPrec [JSONArrayError]
readPrec :: ReadPrec JSONArrayError
$creadPrec :: ReadPrec JSONArrayError
readList :: ReadS [JSONArrayError]
$creadList :: ReadS [JSONArrayError]
readsPrec :: Int -> ReadS JSONArrayError
$creadsPrec :: Int -> ReadS JSONArrayError
Read) via (Map.Map Integer JSONError)
deriving (b -> JSONArrayError -> JSONArrayError
NonEmpty JSONArrayError -> JSONArrayError
JSONArrayError -> JSONArrayError -> JSONArrayError
(JSONArrayError -> JSONArrayError -> JSONArrayError)
-> (NonEmpty JSONArrayError -> JSONArrayError)
-> (forall b. Integral b => b -> JSONArrayError -> JSONArrayError)
-> Semigroup JSONArrayError
forall b. Integral b => b -> JSONArrayError -> JSONArrayError
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: b -> JSONArrayError -> JSONArrayError
$cstimes :: forall b. Integral b => b -> JSONArrayError -> JSONArrayError
sconcat :: NonEmpty JSONArrayError -> JSONArrayError
$csconcat :: NonEmpty JSONArrayError -> JSONArrayError
<> :: JSONArrayError -> JSONArrayError -> JSONArrayError
$c<> :: JSONArrayError -> JSONArrayError -> JSONArrayError
Semigroup, Semigroup JSONArrayError
JSONArrayError
Semigroup JSONArrayError
-> JSONArrayError
-> (JSONArrayError -> JSONArrayError -> JSONArrayError)
-> ([JSONArrayError] -> JSONArrayError)
-> Monoid JSONArrayError
[JSONArrayError] -> JSONArrayError
JSONArrayError -> JSONArrayError -> JSONArrayError
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [JSONArrayError] -> JSONArrayError
$cmconcat :: [JSONArrayError] -> JSONArrayError
mappend :: JSONArrayError -> JSONArrayError -> JSONArrayError
$cmappend :: JSONArrayError -> JSONArrayError -> JSONArrayError
mempty :: JSONArrayError
$cmempty :: JSONArrayError
$cp1Monoid :: Semigroup JSONArrayError
Monoid) via (MergeMap Integer JSONError)
indexErrors :: JSONArrayError -> Map.Map Integer JSONError
indexErrors :: JSONArrayError -> Map Integer JSONError
indexErrors = JSONArrayError -> Map Integer JSONError
coerce
instance FromJSON JSONArrayError where
fromJSON :: f JSONArrayError
fromJSON = Map Integer JSONError -> JSONArrayError
MkJSONArrayError (Map Integer JSONError -> JSONArrayError)
-> f (Map Integer JSONError) -> f JSONArrayError
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (Map Integer JSONError)
forall value (f :: * -> *).
(FromJSON value, JSONParser f) =>
f value
fromJSON
instance ToJSON JSONArrayError where
toJSON :: f JSONArrayError
toJSON = (JSONArrayError -> Map Integer JSONError)
-> f (Map Integer JSONError) -> f JSONArrayError
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap JSONArrayError -> Map Integer JSONError
indexErrors f (Map Integer JSONError)
forall v (f :: * -> *). (ToJSON v, JSONSerializer f) => f v
toJSON
prettyPrintJSONError :: JSONError -> Text
prettyPrintJSONError :: JSONError -> Text
prettyPrintJSONError = (Text -> Text) -> JSONError -> Text
go Text -> Text
forall a. a -> a
id
where
go :: (Text -> Text) -> JSONError -> Text
go :: (Text -> Text) -> JSONError -> Text
go Text -> Text
mapper = \case
ErrorMesage Text
txt -> Text -> Text
mapper Text
txt
JSONError
ErrorInvalidJSON -> Text -> Text
mapper Text
"Invalid JSON"
ErrorBadType JSONType
jt JSONType
jt' -> Text -> Text
mapper Text
"Bad type: Expected " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
pack (JSONType -> String
forall a. Show a => a -> String
show JSONType
jt) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" got " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
pack (JSONType -> String
forall a. Show a => a -> String
show JSONType
jt')
JSONError
ErrorNoValue -> Text -> Text
mapper Text
"Expected to receive a value, but did not"
ErrorBadTextConstant Text
txt Text
txt' -> Text -> Text
mapper Text
"Bad text constant: Expected \"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
txt Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\", got \"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
txt' Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\""
ErrorBadObject (MkJSONObjectError Map Text JSONError
map) -> (Text -> Text -> JSONError -> Text)
-> Text -> Map Text JSONError -> Text
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey (\Text
acc Text
key JSONError
value -> Text
acc Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
mapper Text
key Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (Text -> Text) -> JSONError -> Text
go (Text -> Text
mapper (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>)) JSONError
value) Text
forall a. Monoid a => a
mempty Map Text JSONError
map
ErrorBadArray (MkJSONArrayError Map Integer JSONError
map) -> (Text -> Integer -> JSONError -> Text)
-> Text -> Map Integer JSONError -> Text
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey (\Text
acc Integer
key JSONError
value -> Text
acc Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
mapper (String -> Text
pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Integer -> String
forall a. Show a => a -> String
show Integer
key) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (Text -> Text) -> JSONError -> Text
go (Text -> Text
mapper (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>)) JSONError
value) Text
forall a. Monoid a => a
mempty Map Integer JSONError
map
ErrorChoice Set JSONError
ne -> Text -> Text
mapper Text
"One of:\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (Text -> JSONError -> Text) -> Text -> Set JSONError -> Text
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\Text
acc JSONError
err -> Text
acc Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (Text -> Text) -> JSONError -> Text
go Text -> Text
newMap JSONError
err) Text
forall a. Monoid a => a
mempty Set JSONError
ne
where
newMap :: Text -> Text
newMap = Text -> Text
mapper (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>)