report invalid ISO dates instead of crashing

Sat, 01 Jun 2019 14:17:58 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 01 Jun 2019 14:17:58 +0300
changeset 59
0f3e70a2bb4b
parent 58
86014c443635
child 60
b8fac2477fc8

report invalid ISO dates instead of crashing

header.py file | annotate | diff | comparison | revisions
--- a/header.py	Sat Jun 01 12:38:35 2019 +0300
+++ b/header.py	Sat Jun 01 14:17:58 2019 +0300
@@ -125,8 +125,15 @@
             elif self.try_to_match(
                 r'!HISTORY (\d{4}-\d{2}-\d{2}) ([\[{][^\]}]+[\]}]) (.+)$',
                 'history'):
+                try:
+                    time_object = datetime.datetime.strptime(
+                        self.groups[0],
+                        '%Y-%m-%d',
+                    )
+                except ValueError:
+                    self.parse_error("invalid ISO date in history")
                 result.history.append(HistoryEntry(
-                    date = datetime.datetime.strptime(self.groups[0], '%Y-%m-%d').date(),
+                    date = time_object.date(),
                     user = self.groups[1],
                     text = self.groups[2],
                 ))

mercurial