mirror of
https://github.com/facebook/duckling.git
synced 2024-11-28 00:31:28 +03:00
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:
parent
4b44e969c9
commit
0efbfe5988
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user