summaryrefslogtreecommitdiff
path: root/LocationLog.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-10 00:02:07 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-10 00:02:07 -0400
commite64d1becf429489f8c6ded230e6e17b63a89c483 (patch)
tree086ceb8b6760c899264c67bcf9f0a27e40ea0056 /LocationLog.hs
parent381e6f84e5f4ddc64ed86f08064ebaf2313b18db (diff)
robustness fix
avoid crash if the seconds field is not numeric
Diffstat (limited to 'LocationLog.hs')
-rw-r--r--LocationLog.hs12
1 files changed, 7 insertions, 5 deletions
diff --git a/LocationLog.hs b/LocationLog.hs
index b6c85113d..db1fac144 100644
--- a/LocationLog.hs
+++ b/LocationLog.hs
@@ -20,6 +20,7 @@ module LocationLog where
import Data.DateTime
import System.IO
import System.Directory
+import Data.Char
import GitRepo
import Utility
@@ -50,14 +51,15 @@ instance Read LogLine where
-- This parser is robust in that even unparsable log lines are
-- read without an exception being thrown.
-- Such lines have a status of Undefined.
- readsPrec _ string = if (length w >= 3)
- then [((LogLine date status repo), "")]
- else [((LogLine (fromSeconds 0) Undefined ""), "")]
+ readsPrec _ string =
+ if (length w >= 3 && all isDigit date)
+ then [((LogLine (fromSeconds $ read date) status repo), "")]
+ else [((LogLine (fromSeconds 0) Undefined ""), "")]
where
- date = fromSeconds $ read $ w !! 0
+ w = words string
+ date = w !! 0
status = read $ w !! 1
repo = unwords $ drop 2 w
- w = words string
{- Reads a log file.
- Note that the LogLines returned may be in any order. -}