From f717c53e8be353df52a9f883723f13cad051535c Mon Sep 17 00:00:00 2001
From: 3wc <3wc.git@doesthisthing.work>
Date: Sat, 3 Apr 2021 15:44:29 +0200
Subject: [PATCH] Gracefully handle README-parsing failures

---
 bin/app-json.py | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/bin/app-json.py b/bin/app-json.py
index b9cbbf9..7135057 100755
--- a/bin/app-json.py
+++ b/bin/app-json.py
@@ -137,20 +137,26 @@ def get_app_features(app_path):
         log.info(f"{app_path}/README.md")
         contents = handle.read()
 
-    for match in findall(r"\*\*.*\s\*", contents):
-        title = search(r"(?<=\*\*).*(?=\*\*)", match).group().lower()
+    try:
+        for match in findall(r"\*\*.*\s\*", contents):
+            title = search(r"(?<=\*\*).*(?=\*\*)", match).group().lower()
 
-        if title == "image":
-            value = {
-                "image": search(r"(?<=`).*(?=`)", match).group(),
-                "url": search(r"(?<=\().*(?=\))", match).group(),
-                "rating": match.split(",")[1].strip(),
-                "source": match.split(",")[-1].replace("*", "").strip(),
-            }
-        else:
-            value = match.split(":")[-1].replace("*", "").strip()
+            if title == "image":
+                value = {
+                    "image": search(r"(?<=`).*(?=`)", match).group(),
+                    "url": search(r"(?<=\().*(?=\))", match).group(),
+                    "rating": match.split(",")[1].strip(),
+                    "source": match.split(",")[-1].replace("*", "").strip(),
+                }
+            else:
+                value = match.split(":")[-1].replace("*", "").strip()
 
-        features[title] = value
+            features[title] = value
+    except (IndexError, AttributeError):
+        log.info(f"Can't parse {app_path}/README.md")
+        return {}
+    finally:
+        _run_cmd("git checkout HEAD")
 
     log.info(f"Parsed {features}")