diff --git a/dotdrop/cfg_aggregator.py b/dotdrop/cfg_aggregator.py index 381a388..fa18a44 100644 --- a/dotdrop/cfg_aggregator.py +++ b/dotdrop/cfg_aggregator.py @@ -19,7 +19,8 @@ from dotdrop.profile import Profile from dotdrop.action import Action, Transform from dotdrop.logger import Logger from dotdrop.utils import strip_home, debug_list, debug_dict -from dotdrop.exceptions import UndefinedException, YamlException +from dotdrop.exceptions import UndefinedException, YamlException, \ + ConfigException TILD = '~' @@ -400,7 +401,7 @@ class CfgAggregator: err = f'{container} does not contain' err += f' a {keys} entry named {key}' self.log.err(err) - raise Exception(err) + raise ConfigException(err) objects.append(obj) if not islist: objects = objects[0] diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 14094ce..d1c2b44 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -24,7 +24,8 @@ from dotdrop.utils import get_tmpdir, removepath, \ adapt_workers, check_version, pivot_path from dotdrop.linktypes import LinkTypes from dotdrop.exceptions import YamlException, \ - UndefinedException, UnmetDependency + UndefinedException, UnmetDependency, \ + ConfigException, OptionsException LOG = Logger() TRANS_SUFFIX = 'trans' @@ -877,10 +878,16 @@ def main(): try: opts = Options() except YamlException as exc: - LOG.err(f'config error: {exc}') + LOG.err(f'error (yaml): {exc}') + return False + except ConfigException as exc: + LOG.err(f'error (config): {exc}') return False except UndefinedException as exc: - LOG.err(f'config error: {exc}') + LOG.err(f'error (deps): {exc}') + return False + except OptionsException as exc: + LOG.err(f'error (options): {exc}') return False if opts.debug: diff --git a/dotdrop/exceptions.py b/dotdrop/exceptions.py index 1c2503a..f5df6ed 100644 --- a/dotdrop/exceptions.py +++ b/dotdrop/exceptions.py @@ -10,6 +10,14 @@ class YamlException(Exception): """exception in CfgYaml""" +class ConfigException(Exception): + """exception in config parsing/aggregation""" + + +class OptionsException(Exception): + """dotdrop options exception""" + + class UndefinedException(Exception): """exception in templating""" diff --git a/dotdrop/options.py b/dotdrop/options.py index 00bb3fe..76cd7ee 100644 --- a/dotdrop/options.py +++ b/dotdrop/options.py @@ -20,7 +20,7 @@ from dotdrop.logger import Logger from dotdrop.cfg_aggregator import CfgAggregator from dotdrop.action import Action from dotdrop.utils import uniq_list, debug_list, debug_dict -from dotdrop.exceptions import YamlException +from dotdrop.exceptions import YamlException, OptionsException ENV_PROFILE = 'DOTDROP_PROFILE' ENV_CONFIG = 'DOTDROP_CONFIG' @@ -430,4 +430,4 @@ class Options(AttrMonitor): def _attr_set(self, attr): """error when some inexistent attr is set""" - raise Exception(f'bad option: {attr}') + raise OptionsException(f'bad option: {attr}') diff --git a/dotdrop/utils.py b/dotdrop/utils.py index 01f0d93..dc79987 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -354,6 +354,7 @@ def dependencies_met(): # check python deps # pylint: disable=C0415 + # python-magic name = 'python-magic' err = f'missing python module \"{name}\"' @@ -372,7 +373,7 @@ def dependencies_met(): from docopt import docopt assert docopt except ImportError as exc: - raise Exception(err) from exc + raise UnmetDependency(err) from exc # jinja2 name = 'jinja2' @@ -381,7 +382,7 @@ def dependencies_met(): import jinja2 assert jinja2 except ImportError as exc: - raise Exception(err) from exc + raise UnmetDependency(err) from exc # ruamel.yaml name = 'ruamel.yaml' @@ -390,7 +391,7 @@ def dependencies_met(): from ruamel.yaml import YAML assert YAML except ImportError as exc: - raise Exception(err) from exc + raise UnmetDependency(err) from exc # toml name = 'toml' @@ -399,7 +400,7 @@ def dependencies_met(): import toml assert toml except ImportError as exc: - raise Exception(err) from exc + raise UnmetDependency(err) from exc # distro name = 'distro' @@ -408,7 +409,7 @@ def dependencies_met(): import distro assert distro except ImportError as exc: - raise Exception(err) from exc + raise UnmetDependency(err) from exc # pylint: enable=C0415