plugin: catch errors when loading resource files

This commit is contained in:
dece 2020-10-09 21:59:21 +02:00
parent 7eca5da533
commit 93288d3599

View file

@ -30,8 +30,11 @@ class Plugin:
resources_dir = self.bot.config["resources_dir"]
for key, resource_path in config.get("resources", {}).items():
resource_path = Path(resources_dir) / resource_path
with open(resource_path, "rt") as resource_file:
config[key] = [l.strip() for l in resource_file.readlines()]
try:
with open(resource_path, "rt") as resource_file:
config[key] = [l.strip() for l in resource_file.readlines()]
except OSError:
self.bot.log_e(f"Could not load resource at {resource_path}.")
return config
def check_config(self):
@ -39,7 +42,7 @@ class Plugin:
missing = False
for key in self.REQUIRED_CONFIGS:
if key not in self.config:
self.bot.log_w(f"Missing '{key}' in {self.name} configuration.")
self.bot.log_e(f"Missing '{key}' in {self.name} configuration.")
missing = True
return not missing