git.iko.soy/typeable/postgresql-simple
on master help sign in
Merge pull request #2 from sol/better-json-errors

fromJSONField: Include JSONPath on JSON parse errors

commit466c46904b54121f9351af31762c13133c67be33 authorOleg Grenrus <oleg.grenrus@iki.fi> dateWed 28 Nov 2018, 10:50 (8 years ago) parentcc6808d1938872
1 file changed+6−5
src/Database/PostgreSQL/Simple/FromField.hs+6−5
src/Database/PostgreSQL/Simple/FromField.hs+6−5
@@ -117,6 +117,7 @@ import Control.Applicative ( (<|>), (<$>), pure, (*>), (<*) )
117117import Control.Concurrent.MVar (MVar, newMVar)
118118import Control.Exception (Exception)
119119import qualified Data.Aeson as JSON
120+import qualified Data.Aeson.Internal as JSON
120121import qualified Data.Aeson.Parser as JSON (value')
121122import Data.Attoparsec.ByteString.Char8 hiding (Result)
122123import Data.ByteString (ByteString)
@@ -567,7 +568,7 @@ fromFieldJSONByteString f mbs =
567568 Just bs -> pure bs
568569
569570-- | Parse a field to a JSON 'JSON.Value' and convert that into a
570−-- Haskell value using 'JSON.fromJSON'.
571+-- Haskell value using the 'JSON.FromJSON' instance.
571572--
572573-- This can be used as the default implementation for the 'fromField'
573574-- method for Haskell types that have a JSON representation in
@@ -588,10 +589,10 @@ fromFieldJSONByteString f mbs =
588589fromJSONField :: (JSON.FromJSON a, Typeable a) => FieldParser a
589590fromJSONField f mbBs = do
590591 value <- fromField f mbBs
591− case JSON.fromJSON value of
592− JSON.Error err -> returnError ConversionFailed f $
593− "JSON decoding error: " ++ err
594− JSON.Success x -> pure x
592+ case JSON.ifromJSON value of
593+ JSON.IError path err -> returnError ConversionFailed f $
594+ "JSON decoding error: " ++ (JSON.formatError path err)
595+ JSON.ISuccess x -> pure x
595596
596597-- | Compatible with the same set of types as @a@. Note that
597598-- modifying the 'IORef' does not have any effects outside