1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 19:09:44 +00:00

exceptions and linting

This commit is contained in:
deadc0de6
2023-02-05 17:58:40 +01:00
committed by deadc0de
parent 82cdbc3703
commit 43b2d9ec54
5 changed files with 29 additions and 12 deletions

View File

@@ -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]

View File

@@ -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:

View File

@@ -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"""

View File

@@ -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}')

View File

@@ -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