diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2012-07-21 16:02:25 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2012-07-21 16:02:25 +0100 |
commit | 9a4158ebe38c40d7897c12be9b5257caec5e1293 (patch) | |
tree | 39074cc013d706e96b60aae7f1ce97bb25b9bec8 /alot/settings | |
parent | c7d5f14c01957e8aa4d3e0a9da1082280598c5e1 (diff) |
better validation error reports
Diffstat (limited to 'alot/settings')
-rw-r--r-- | alot/settings/__init__.py | 6 | ||||
-rw-r--r-- | alot/settings/theme.py | 2 | ||||
-rw-r--r-- | alot/settings/utils.py | 20 |
3 files changed, 20 insertions, 8 deletions
diff --git a/alot/settings/__init__.py b/alot/settings/__init__.py index 8205d099..dc729b0e 100644 --- a/alot/settings/__init__.py +++ b/alot/settings/__init__.py @@ -95,7 +95,11 @@ class SettingsManager(object): raise ConfigError(err_msg % (themestring, themes_dir)) else: theme_path = os.path.join(themes_dir, themestring) - self._theme = Theme(theme_path) + try: + self._theme = Theme(theme_path) + except ConfigError as e: + err_msg = 'Theme file %s failed validation:\n' + raise ConfigError((err_msg % themestring) + e.message) self._accounts = self._parse_accounts(self._config) self._accountmap = self._account_table(self._accounts) diff --git a/alot/settings/theme.py b/alot/settings/theme.py index ea154504..78f86fc5 100644 --- a/alot/settings/theme.py +++ b/alot/settings/theme.py @@ -39,7 +39,7 @@ class Theme(object): indefault = set(threadline.sections) diff = listed.difference(here.union(indefault)) if diff: - msg = 'missing threadline parts: %s' % diff + msg = 'missing threadline parts: %s' % ', '.join(diff) raise ConfigError(msg) def get_attribute(self, colourmode, mode, name, part=None): diff --git a/alot/settings/utils.py b/alot/settings/utils.py index accc3ab8..0236cf58 100644 --- a/alot/settings/utils.py +++ b/alot/settings/utils.py @@ -24,21 +24,29 @@ def read_config(configpath=None, specpath=None, checks={}): config = ConfigObj(infile=configpath, configspec=specpath, file_error=True, encoding='UTF8') except (ConfigObjError, IOError), e: - raise ConfigError('Could not read "%s": %s' % (configpath, e)) + raise ConfigError('Couls not read %s' % configpath) + except UnboundLocalError as e: + # this works around a bug in configobj + msg = '%s is malformed. Check for sections without parents..' + raise ConfigError(msg % configpath) if specpath: validator = Validator() validator.functions.update(checks) - results = config.validate(validator) + results = config.validate(validator, preserve_errors=True) if results != True: - error_msg = 'Validation errors occurred:\n' + error_msg = '' for (section_list, key, res) in flatten_errors(config, results): if key is not None: - msg = 'key "%s" in section "%s" failed validation: %s' - msg = msg % (key, ', '.join(section_list), res) + if res == False: + msg = 'key "%s" in section "%s" is missing.' + msg = msg % (key, ', '.join(section_list)) + else: + msg = 'key "%s" in section "%s" failed validation: %s' + msg = msg % (key, ', '.join(section_list), res) else: - msg = 'section "%s" is malformed' % ', '.join(section_list) + msg = 'section "%s" is missing' % '.'.join(section_list) error_msg += msg + '\n' raise ConfigError(error_msg) return config |