robustness fix

avoid crash if the seconds field is not numeric
This commit is contained in:
Joey Hess 2010-10-10 00:02:07 -04:00
parent 381e6f84e5
commit e64d1becf4

View file

@ -20,6 +20,7 @@ module LocationLog where
import Data.DateTime import Data.DateTime
import System.IO import System.IO
import System.Directory import System.Directory
import Data.Char
import GitRepo import GitRepo
import Utility import Utility
@ -50,14 +51,15 @@ instance Read LogLine where
-- This parser is robust in that even unparsable log lines are -- This parser is robust in that even unparsable log lines are
-- read without an exception being thrown. -- read without an exception being thrown.
-- Such lines have a status of Undefined. -- Such lines have a status of Undefined.
readsPrec _ string = if (length w >= 3) readsPrec _ string =
then [((LogLine date status repo), "")] if (length w >= 3 && all isDigit date)
else [((LogLine (fromSeconds 0) Undefined ""), "")] then [((LogLine (fromSeconds $ read date) status repo), "")]
else [((LogLine (fromSeconds 0) Undefined ""), "")]
where where
date = fromSeconds $ read $ w !! 0 w = words string
date = w !! 0
status = read $ w !! 1 status = read $ w !! 1
repo = unwords $ drop 2 w repo = unwords $ drop 2 w
w = words string
{- Reads a log file. {- Reads a log file.
- Note that the LogLines returned may be in any order. -} - Note that the LogLines returned may be in any order. -}