Give a usable error if we fail to parse reftime parameter

Summary:
My attention was brought to this issue by the linter complaining about `read`.

The linter is just as happy with `error`, but I do think it's better to fail
with a usable error message here than with whatever error `read` gives us.

Reviewed By: chessai

Differential Revision: D28213406

fbshipit-source-id: f101d0515ee64978480bdbb873ff72d80d124969
This commit is contained in:
Steven Troxler 2021-05-07 06:18:51 -07:00 committed by Facebook GitHub Bot
parent 4b44e969c9
commit 0efbfe5988

View File

@ -160,8 +160,10 @@ parseHandler tzs = do
parseRefTime :: Text -> ByteString -> DucklingTime
parseRefTime timezone refTime = makeReftime tzs timezone utcTime
where
msec = read $ Text.unpack $ Text.decodeUtf8 refTime
utcTime = posixSecondsToUTCTime $ fromInteger msec / 1000
milliseconds = readMaybe $ Text.unpack $ Text.decodeUtf8 refTime
utcTime = case milliseconds of
Just msec -> posixSecondsToUTCTime $ fromInteger msec / 1000
Nothing -> error "Please use milliseconds since epoch for reftime"
parseLatent :: Maybe ByteString -> Bool
parseLatent x = fromMaybe defaultLatent