plugin: catch errors when loading resource files

master
dece 4 years ago
parent 7eca5da533
commit 93288d3599

@ -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

Loading…
Cancel
Save