aeson-better-errors 0.3.0.0 → 0.4.0.0
raw patch · 3 files changed
+22/−3 lines, 3 filesdep +voidPVP ok
version bump matches the API change (PVP)
Dependencies added: void
API changes (from Hackage documentation)
+ Data.Aeson.BetterErrors: toAesonParser' :: Parse' a -> Value -> Parser a
+ Data.Aeson.BetterErrors: type Parse' = Parse Void
+ Data.Aeson.BetterErrors.Internal: toAesonParser' :: Parse' a -> Value -> Parser a
+ Data.Aeson.BetterErrors.Internal: type Parse' = Parse Void
Files
- aeson-better-errors.cabal +2/−1
- src/Data/Aeson/BetterErrors.hs +2/−0
- src/Data/Aeson/BetterErrors/Internal.hs +18/−2
aeson-better-errors.cabal view
@@ -1,5 +1,5 @@ name: aeson-better-errors-version: 0.3.0.0+version: 0.4.0.0 synopsis: Better error messages when decoding JSON values. license: MIT license-file: LICENSE@@ -35,6 +35,7 @@ , vector , transformers , mtl+ , void ghc-options: -Wall hs-source-dirs: src
src/Data/Aeson/BetterErrors.hs view
@@ -14,6 +14,7 @@ module Data.Aeson.BetterErrors ( -- * The Parser type Parse+ , Parse' -- * Basic parsers , asText@@ -64,6 +65,7 @@ -- * Miscellaneous , toAesonParser+ , toAesonParser' , JSONType(..) , jsonTypeOf ) where
src/Data/Aeson/BetterErrors/Internal.hs view
@@ -9,6 +9,7 @@ import Control.Monad.Trans.Except import Control.Monad.Error.Class (MonadError(..)) +import Data.Void import Data.Foldable (foldMap) import Data.Monoid import Data.DList (DList)@@ -32,13 +33,22 @@ -- | The type of parsers: things which consume JSON values and produce either -- detailed errors or successfully parsed values (of other types). ----- The @err@ type parameter is for your own errors; if you don't need to use--- any errors of your own, simply set it to @()@.+-- The @err@ type parameter is for custom validation errors; for parsers that+-- don't produce any custom validation errors, I recommend you just stick a+-- type variable in for full generality:+--+-- @+-- asTuple :: Parse e (Int, Int)+-- asTuple = (,) \<$\> nth 0 asIntegral \<*\> nth 1 asIntegral+-- @ newtype Parse err a = Parse (ReaderT ParseReader (Except (ParseError err)) a) deriving (Functor, Applicative, Monad, MonadReader ParseReader, MonadError (ParseError err)) +-- | The type of parsers which never produce custom validation errors.+type Parse' = Parse Void+ runParser :: (s -> Either String A.Value) -> Parse err a ->@@ -78,6 +88,12 @@ case parseValue p val of Right x -> return x Left err -> fail (unlines (map T.unpack (displayError showCustom err)))++-- | Take a parser which never produces custom validation errors and turn+-- it into an Aeson parser. Note that in this case, there is no need to provide+-- a display function.+toAesonParser' :: Parse' a -> A.Value -> A.Parser a+toAesonParser' = toAesonParser absurd -- | Data used internally by the 'Parse' type. data ParseReader = ParseReader