on master help sign in
Improve error message on day parse fail

Before: *> parse utcTime "asd" Fail "asd" [] "Failed reading: takeWhile1" After: *> parse utcTime "asd" Fail "asd" [] "Failed reading: date must be of form [+,-]YYYY-MM-DD" There's probably a better don't-repeat-yourself refactor here of the error message, but my parsec-fu is not strong. This is important in particular because this parser's error messages often get sent directly to users when serving json APIs via aeson.

commit556c1f14c2cd9f6cfc55724025629c8bf566a2f5 authorgbaz <gershomb@gmail.com> dateThu 28 Dec 2017, 14:33 (9 years ago) parent1a845c8
1 file changed+3−3
attoparsec-iso8601/Data/Attoparsec/Time.hs+3−3
attoparsec-iso8601/Data/Attoparsec/Time.hs+3−3
@@ -42,9 +42,9 @@ import qualified Data.Time.LocalTime as Local
4242day :: Parser Day
4343day = do
4444 absOrNeg <- negate <$ char '-' <|> id <$ char '+' <|> pure id
45− y <- decimal <* char '-'
46− m <- twoDigits <* char '-'
47− d <- twoDigits
45+ y <- (decimal <* char '-') <|> fail "date must be of form [+,-]YYYY-MM-DD"
46+ m <- (twoDigits <* char '-') <|> fail "date must be of form [+,-]YYYY-MM-DD"
47+ d <- twoDigits <|> fail "date must be of form [+,-]YYYY-MM-DD"
4848 maybe (fail "invalid date") return (fromGregorianValid (absOrNeg y) m d)
4949
5050-- | Parse a two-digit integer (e.g. day of month, hour).