From f0d91a67e9fcdccaddfaad3204426a7caa17bf5d Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 4 Feb 2021 14:44:48 +0100 Subject: 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. --- alot/settings/manager.py | 17 +++++++++++------ 1 file 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']) -- cgit v1.2.3