Error checking for loading cache json file

This commit is contained in:
Dylan 2022-05-22 15:19:28 +01:00
parent 014f9d0e8d
commit 55c956ad4e

View file

@ -74,9 +74,18 @@ if link_cache_system == "json":
default_link_cache = {"test":"test"} default_link_cache = {"test":"test"}
json.dump(default_link_cache, outfile, indent=4, sort_keys=True) json.dump(default_link_cache, outfile, indent=4, sort_keys=True)
f = open('links.json',) try:
link_cache = json.load(f) f = open('links.json',)
f.close() link_cache = json.load(f)
except json.decoder.JSONDecodeError:
print(" ➤ [ X ] Failed to load cache JSON file. Creating new file.")
link_cache = {}
except FileNotFoundError:
print(" ➤ [ X ] Failed to load cache JSON file. Creating new file.")
link_cache = {}
finally:
f.close()
elif link_cache_system == "db": elif link_cache_system == "db":
client = pymongo.MongoClient(config['config']['database'], connect=False) client = pymongo.MongoClient(config['config']['database'], connect=False)
table = config['config']['table'] table = config['config']['table']