mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-16 19:40:15 +00:00
properly handle bad config
This commit is contained in:
@@ -1340,7 +1340,7 @@ class CfgYaml:
|
|||||||
def _validate(self, yamldict):
|
def _validate(self, yamldict):
|
||||||
"""validate entries"""
|
"""validate entries"""
|
||||||
if not yamldict:
|
if not yamldict:
|
||||||
return
|
raise YamlException('empty config file')
|
||||||
|
|
||||||
# check top entries
|
# check top entries
|
||||||
for entry in self.top_entries:
|
for entry in self.top_entries:
|
||||||
@@ -1352,15 +1352,15 @@ class CfgYaml:
|
|||||||
# check link_dotfile_default
|
# check link_dotfile_default
|
||||||
if self.key_settings not in yamldict:
|
if self.key_settings not in yamldict:
|
||||||
# no configs top entry
|
# no configs top entry
|
||||||
return
|
raise YamlException(f'no \"{self.key_settings}\" key found')
|
||||||
if not yamldict[self.key_settings]:
|
if not yamldict[self.key_settings]:
|
||||||
# configs empty
|
# configs empty
|
||||||
return
|
raise YamlException(f'empty \"{self.key_settings}\" key')
|
||||||
|
|
||||||
# check settings values
|
# check settings values
|
||||||
settings = yamldict[self.key_settings]
|
settings = yamldict[self.key_settings]
|
||||||
if self.key_settings_link_dotfile_default not in 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]
|
val = settings[self.key_settings_link_dotfile_default]
|
||||||
if val not in self.allowed_link_val:
|
if val not in self.allowed_link_val:
|
||||||
err = f'bad link value: {val}'
|
err = f'bad link value: {val}'
|
||||||
|
|||||||
@@ -935,16 +935,16 @@ def main():
|
|||||||
try:
|
try:
|
||||||
opts = Options()
|
opts = Options()
|
||||||
except YamlException as exc:
|
except YamlException as exc:
|
||||||
LOG.err(f'error (yaml): {exc}')
|
LOG.err(f'yaml error: {exc}')
|
||||||
return False
|
return False
|
||||||
except ConfigException as exc:
|
except ConfigException as exc:
|
||||||
LOG.err(f'error (config): {exc}')
|
LOG.err(f'config error: {exc}')
|
||||||
return False
|
return False
|
||||||
except UndefinedException as exc:
|
except UndefinedException as exc:
|
||||||
LOG.err(f'error (deps): {exc}')
|
LOG.err(f'dependencies error: {exc}')
|
||||||
return False
|
return False
|
||||||
except OptionsException as exc:
|
except OptionsException as exc:
|
||||||
LOG.err(f'error (options): {exc}')
|
LOG.err(f'options error: {exc}')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if opts.debug:
|
if opts.debug:
|
||||||
|
|||||||
@@ -167,12 +167,14 @@ class Options(AttrMonitor):
|
|||||||
# selected profile
|
# selected profile
|
||||||
self.profile = self.args['--profile']
|
self.profile = self.args['--profile']
|
||||||
self.confpath = self._get_config_path()
|
self.confpath = self._get_config_path()
|
||||||
|
if not self.confpath:
|
||||||
|
raise YamlException('no config file found')
|
||||||
self.confpath = os.path.abspath(self.confpath)
|
self.confpath = os.path.abspath(self.confpath)
|
||||||
self.log.dbg(f'config abs path: {self.confpath}')
|
self.log.dbg(f'config abs path: {self.confpath}')
|
||||||
if not self.confpath:
|
if not self.confpath:
|
||||||
raise YamlException('no config file found')
|
raise YamlException('no config file found')
|
||||||
if not os.path.exists(self.confpath):
|
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)
|
raise YamlException(err)
|
||||||
self.log.dbg('#################################################')
|
self.log.dbg('#################################################')
|
||||||
self.log.dbg('#################### DOTDROP ####################')
|
self.log.dbg('#################### DOTDROP ####################')
|
||||||
|
|||||||
Reference in New Issue
Block a user