From 9215522563faaeca29335c6881fd18d06936565a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Wed, 29 Sep 2021 15:05:31 +0200 Subject: [PATCH] fix: Avoid exception in case the DNS files are broken --- lookyloo/capturecache.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lookyloo/capturecache.py b/lookyloo/capturecache.py index 69bd580c..aa0aae25 100644 --- a/lookyloo/capturecache.py +++ b/lookyloo/capturecache.py @@ -321,13 +321,21 @@ class CapturesIndex(Mapping): ips_path = ct.root_hartree.har.path.parent / 'ips.json' host_cnames: Dict[str, Optional[str]] = {} if cnames_path.exists(): - with cnames_path.open() as f: - host_cnames = json.load(f) + try: + with cnames_path.open() as f: + host_cnames = json.load(f) + except json.decoder.JSONDecodeError: + # The json is broken, delete and re-trigger the requests + host_cnames = {} host_ips: Dict[str, List[str]] = {} if ips_path.exists(): - with ips_path.open() as f: - host_ips = json.load(f) + try: + with ips_path.open() as f: + host_ips = json.load(f) + except json.decoder.JSONDecodeError: + # The json is broken, delete and re-trigger the requests + host_ips = {} for node in ct.root_hartree.hostname_tree.traverse(): if node.name not in host_cnames or node.name not in host_ips: