From 50b341baabb86cb3cee52c98ddc515835d1794b9 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Mon, 12 Apr 2021 16:51:45 -0400 Subject: [PATCH] bail out if old index.json is found during init but doesnt contain links --- archivebox/index/json.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/archivebox/index/json.py b/archivebox/index/json.py index 6d564ae8..61696b1c 100644 --- a/archivebox/index/json.py +++ b/archivebox/index/json.py @@ -60,7 +60,19 @@ def parse_json_main_index(out_dir: Path=OUTPUT_DIR) -> Iterator[Link]: index_path = Path(out_dir) / JSON_INDEX_FILENAME if index_path.exists(): with open(index_path, 'r', encoding='utf-8') as f: - links = pyjson.load(f)['links'] + try: + links = pyjson.load(f)['links'] + if links: + Link.from_json(links[0]) + except Exception as err: + print(" {lightyellow}! Found an index.json in the project root but couldn't load links from it: {} {}".format( + index_path, + err.__class__.__name__, + err, + **ANSI, + )) + return () + for link_json in links: try: yield Link.from_json(link_json)