summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-02-04 14:44:48 +0100
committerAnton Khirnov <anton@khirnov.net>2021-02-04 14:44:48 +0100
commitf0d91a67e9fcdccaddfaad3204426a7caa17bf5d (patch)
tree052c72e9fae4c3124864c73da97691224a206995
parentb881e87496b9463e3ca9a48abdfe9a7e5df83230 (diff)
settings/manager: do not report an exception when hooks file is missing
That is a normal situation, just log an info message. Raise an exception when the hooks file exists but cannot be loaded.
-rw-r--r--alot/settings/manager.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/alot/settings/manager.py b/alot/settings/manager.py
index e5dcc4b3..badda2af 100644
--- a/alot/settings/manager.py
+++ b/alot/settings/manager.py
@@ -135,12 +135,17 @@ class SettingsManager:
self._config.walk(self._expand_config_values)
hooks_path = os.path.expanduser(self._config.get('hooksfile'))
- try:
- spec = importlib.util.spec_from_file_location('hooks', hooks_path)
- self.hooks = importlib.util.module_from_spec(spec)
- spec.loader.exec_module(self.hooks)
- except:
- logging.exception('unable to load hooks file:%s', hooks_path)
+ if os.path.isfile(hooks_path):
+ try:
+ spec = importlib.util.spec_from_file_location('hooks', hooks_path)
+ self.hooks = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(self.hooks)
+ except Exception as e:
+ self.hooks = None
+ raise ConfigError('Error loading hooks: %s' % str(e)) from e
+ else:
+ logging.info('Hooks file does not exist')
+
if 'bindings' in newconfig:
self._update_bindings(newconfig['bindings'])