plugin: catch errors when loading resource files
This commit is contained in:
parent
7eca5da533
commit
93288d3599
|
@ -30,8 +30,11 @@ class Plugin:
|
||||||
resources_dir = self.bot.config["resources_dir"]
|
resources_dir = self.bot.config["resources_dir"]
|
||||||
for key, resource_path in config.get("resources", {}).items():
|
for key, resource_path in config.get("resources", {}).items():
|
||||||
resource_path = Path(resources_dir) / resource_path
|
resource_path = Path(resources_dir) / resource_path
|
||||||
|
try:
|
||||||
with open(resource_path, "rt") as resource_file:
|
with open(resource_path, "rt") as resource_file:
|
||||||
config[key] = [l.strip() for l in resource_file.readlines()]
|
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
|
return config
|
||||||
|
|
||||||
def check_config(self):
|
def check_config(self):
|
||||||
|
@ -39,7 +42,7 @@ class Plugin:
|
||||||
missing = False
|
missing = False
|
||||||
for key in self.REQUIRED_CONFIGS:
|
for key in self.REQUIRED_CONFIGS:
|
||||||
if key not in self.config:
|
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
|
missing = True
|
||||||
return not missing
|
return not missing
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue