Skip to content

Commit 1938872

Browse files
committed
fromJSONField: Include JSONPath on JSON parse errors
1 parent cc6808d commit 1938872

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Database/PostgreSQL/Simple/FromField.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ import Control.Applicative ( (<|>), (<$>), pure, (*>), (<*) )
117117
import Control.Concurrent.MVar (MVar, newMVar)
118118
import Control.Exception (Exception)
119119
import qualified Data.Aeson as JSON
120+
import qualified Data.Aeson.Internal as JSON
120121
import qualified Data.Aeson.Parser as JSON (value')
121122
import Data.Attoparsec.ByteString.Char8 hiding (Result)
122123
import 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 =
588589
fromJSONField :: (JSON.FromJSON a, Typeable a) => FieldParser a
589590
fromJSONField 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

0 commit comments

Comments
 (0)