From 76d1b14eaf222cb084aa57e4b0105ed205482dc9 Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Sun, 23 Jul 2023 19:55:59 +0000 Subject: [PATCH] Ignore missing sites.json gracefully --- src/Site/Site.py | 6 +++++- src/Site/SiteManager.py | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Site/Site.py b/src/Site/Site.py index ffdb2bb0..ae2be36a 100644 --- a/src/Site/Site.py +++ b/src/Site/Site.py @@ -87,7 +87,11 @@ class Site(object): # Load site settings from data/sites.json def loadSettings(self, settings=None): if not settings: - settings = json.load(open("%s/sites.json" % config.data_dir)).get(self.address) + try: + settings = json.load(open(f'{config.data_dir}/sites.json')).get(self.address) + except Exception as err: + logging.error(f'Error loading {config.data_dir}/sites.json: {err}') + settings = {} if settings: self.settings = settings if "cache" not in settings: diff --git a/src/Site/SiteManager.py b/src/Site/SiteManager.py index d7ba6e94..78c20f86 100644 --- a/src/Site/SiteManager.py +++ b/src/Site/SiteManager.py @@ -31,17 +31,18 @@ class SiteManager(object): @util.Noparallel() def load(self, cleanup=True, startup=False): from .Site import Site - self.log.info("Loading sites... (cleanup: %s, startup: %s)" % (cleanup, startup)) + self.log.info(f'Loading sites... ({cleanup=}, {startup=})') self.loaded = False address_found = [] added = 0 load_s = time.time() # Load new adresses try: - json_path = "%s/sites.json" % config.data_dir + json_path = f"{config.data_dir}/sites.json" data = json.load(open(json_path)) except Exception as err: - raise Exception("Unable to load %s: %s" % (json_path, err)) + self.log.error(f"Unable to load {json_path}: {err}") + data = {} sites_need = []