git.iko.soy/typeable/http-api-data
on master help sign in
Improve parse error message for numbers
397b129Nickolay Kudasov
Web/HttpApiData/Internal.hs+2−2
@@ -84,7 +84,7 @@ toUrlPieces = fmap toUrlPiece
84-- >>> parseUrlPieces ["true", "false"] :: Either Text [Bool]
84-- >>> parseUrlPieces ["true", "false"] :: Either Text [Bool]
85-- Right [True,False]
85-- Right [True,False]
86-- >>> parseUrlPieces ["123", "hello", "world"] :: Either Text [Int]
86-- >>> parseUrlPieces ["123", "hello", "world"] :: Either Text [Int]
87−-- Left "input does not start with a digit"
87+-- Left "could not parse: `hello' (input does not start with a digit)"
88parseUrlPieces :: (Traversable t, FromHttpApiData a) => t Text -> Either Text (t a)
88parseUrlPieces :: (Traversable t, FromHttpApiData a) => t Text -> Either Text (t a)
89parseUrlPieces = traverse parseUrlPiece
89parseUrlPieces = traverse parseUrlPiece
90
90
@@ -304,7 +304,7 @@ readTextData = parseMaybeTextData (readMaybe . T.unpack)
304runReader :: Reader a -> Text -> Either Text a
304runReader :: Reader a -> Text -> Either Text a
305runReader reader input =
305runReader reader input =
306 case reader input of
306 case reader input of
307− Left err -> Left (T.pack err)
307+ Left err -> Left ("could not parse: `" <> input <> "' (" <> T.pack err <> ")")
308 Right (x, rest)
308 Right (x, rest)
309 | T.null rest -> Right x
309 | T.null rest -> Right x
310 | otherwise -> defaultParseError input
310 | otherwise -> defaultParseError input