From 91005c44d0287a5b89c214fd05d349c879ee325d Mon Sep 17 00:00:00 2001
From: Leonard Penzer <leonard@penzer.de>
Date: Mon, 6 Jan 2020 09:50:23 +0000
Subject: [PATCH] do not abort when parsing record fails

We have many records in the access.log which cannot be parsed, i.e.
because some people mistype URLs or whatever. Because of that we should
not stop when we encounter an invalid record, but just print a message
and continue parsing the rest of the accesslog.
---
 update_checker.py | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/update_checker.py b/update_checker.py
index ce973c9..7bea273 100755
--- a/update_checker.py
+++ b/update_checker.py
@@ -38,6 +38,10 @@ def ipv62mac(ipv6):
 
     return ":".join(macParts)
 
+class LogRecordParseError(Exception):
+    def __init__(self, record_line):
+        self.record_line = record_line
+
 class LogRecord:
     def __init__(self,record):
         record = record.replace("%2B","+")
@@ -46,9 +50,7 @@ class LogRecord:
         try:
             groups = result.groups()
         except:
-            print(record)
-            print("error parsing record")
-            sys.exit(1)
+            raise LogRecordParseError(record)
         self.ipv6 = groups[0]
         self.date = groups[1]
         self.branch = groups[2]
@@ -94,7 +96,12 @@ if not os.path.isfile(nodesdbFilename):
 data = json.load(open(nodesdbFilename))
 
 for download in allFirmwareDownloads:
-    r = LogRecord(download)
+    try:
+        r = LogRecord(download)
+    except LogRecordParseError as e:
+        print("error parsing line, skipping: {}".format(e.record_line))
+        continue
+
     mac = ipv62mac(r.ipv6)
 
     if mac in data:
-- 
GitLab