From 9fe0f49bbd0699a5660c130bcb100a498af13e18 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Wed, 23 Oct 2024 11:58:51 +0200 Subject: [PATCH] properly handle bad config --- dotdrop/cfg_yaml.py | 8 ++++---- dotdrop/dotdrop.py | 8 ++++---- dotdrop/options.py | 4 +++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/dotdrop/cfg_yaml.py b/dotdrop/cfg_yaml.py index 5d2c701c..413b1601 100644 --- a/dotdrop/cfg_yaml.py +++ b/dotdrop/cfg_yaml.py @@ -1340,7 +1340,7 @@ def _load_yaml(self, path): def _validate(self, yamldict): """validate entries""" if not yamldict: - return + raise YamlException('empty config file') # check top entries for entry in self.top_entries: @@ -1352,15 +1352,15 @@ def _validate(self, yamldict): # check link_dotfile_default if self.key_settings not in yamldict: # no configs top entry - return + raise YamlException(f'no \"{self.key_settings}\" key found') if not yamldict[self.key_settings]: # configs empty - return + raise YamlException(f'empty \"{self.key_settings}\" key') # check settings values settings = yamldict[self.key_settings] if self.key_settings_link_dotfile_default not in settings: - return + raise YamlException(f'no \"{self.key_settings_link_dotfile_default}\" key found') val = settings[self.key_settings_link_dotfile_default] if val not in self.allowed_link_val: err = f'bad link value: {val}' diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 9f605925..ade54f21 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -935,16 +935,16 @@ def main(): try: opts = Options() except YamlException as exc: - LOG.err(f'error (yaml): {exc}') + LOG.err(f'yaml error: {exc}') return False except ConfigException as exc: - LOG.err(f'error (config): {exc}') + LOG.err(f'config error: {exc}') return False except UndefinedException as exc: - LOG.err(f'error (deps): {exc}') + LOG.err(f'dependencies error: {exc}') return False except OptionsException as exc: - LOG.err(f'error (options): {exc}') + LOG.err(f'options error: {exc}') return False if opts.debug: diff --git a/dotdrop/options.py b/dotdrop/options.py index 3ead9714..972bf151 100644 --- a/dotdrop/options.py +++ b/dotdrop/options.py @@ -159,12 +159,14 @@ def __init__(self, args=None): # selected profile self.profile = self.args['--profile'] self.confpath = self._get_config_path() + if not self.confpath: + raise YamlException('no config file found') self.confpath = os.path.abspath(self.confpath) self.log.dbg(f'config abs path: {self.confpath}') if not self.confpath: raise YamlException('no config file found') if not os.path.exists(self.confpath): - err = f'bad config file path: {self.confpath}' + err = f'config does not exist \"{self.confpath}\"' raise YamlException(err) self.log.dbg('#################################################') self.log.dbg('#################### DOTDROP ####################')