packages feed

aeson-better-errors 0.6.0.0 → 0.7.0.0

raw patch · 3 files changed

+22/−1 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Aeson.BetterErrors: FromAeson :: String -> ErrorSpecifics err
+ Data.Aeson.BetterErrors: fromAesonParser :: FromJSON a => Parse e a
+ Data.Aeson.BetterErrors.Internal: FromAeson :: String -> ErrorSpecifics err
+ Data.Aeson.BetterErrors.Internal: fromAesonParser :: FromJSON a => Parse e a

Files

aeson-better-errors.cabal view
@@ -1,5 +1,5 @@ name:                aeson-better-errors-version:             0.6.0.0+version:             0.7.0.0 synopsis:            Better error messages when decoding JSON values. license:             MIT license-file:        LICENSE
src/Data/Aeson/BetterErrors.hs view
@@ -74,6 +74,7 @@   -- * Miscellaneous   , toAesonParser   , toAesonParser'+  , fromAesonParser   , JSONType(..)   , jsonTypeOf   ) where
src/Data/Aeson/BetterErrors/Internal.hs view
@@ -109,6 +109,16 @@ toAesonParser' :: Parse' a -> A.Value -> A.Parser a toAesonParser' = toAesonParser absurd +-- | Create a parser for any type, using its FromJSON instance.  Generally, you+-- should prefer to write parsers using the other functions in this module;+-- 'key', 'asString', etc, since they will usually generate better error+-- messages. However this function is also useful occasionally.+fromAesonParser :: A.FromJSON a => Parse e a+fromAesonParser = liftParse $ \v ->+  case A.fromJSON v of+    A.Success x -> Right x+    A.Error err -> Left (FromAeson err)+ -- | Data used internally by the 'Parse' type. data ParseReader = ParseReader   { rdrPath  :: DList PathPiece@@ -132,7 +142,12 @@ -- | A value indicating that the JSON could not be decoded successfully. data ParseError err   = InvalidJSON String+    -- ^ Indicates a syntax error in the JSON string. Unfortunately, in this+    -- case, Aeson's errors are not very helpful.   | BadSchema [PathPiece] (ErrorSpecifics err)+    -- ^ Indicates a decoding error; the input was parsed as JSON successfully,+    -- but a value of the required type could not be constructed, perhaps+    -- because of a missing key or type mismatch.   deriving (Show, Eq, Functor)  -- | The type of parse errors which never involve custom validation@@ -147,6 +162,7 @@   | OutOfBounds Int   | WrongType JSONType A.Value -- ^ Expected type, actual value   | ExpectedIntegral Double+  | FromAeson String -- ^ An error arising inside a 'A.FromJSON' instance.   | CustomError err   deriving (Show, Eq, Functor) @@ -207,6 +223,10 @@   ] displaySpecifics _ (ExpectedIntegral x) =   [ "Expected an integral value, got " <> tshow x ]+displaySpecifics _ (FromAeson str) =+  [ "Arising from an Aeson FromJSON instance:"+  , T.pack str+  ] displaySpecifics f (CustomError err) =   [ f err ]