From 1bee34e6bcf372989e6ba424fe87559410debec9 Mon Sep 17 00:00:00 2001 From: Sebastian Goscik Date: Wed, 21 Sep 2016 14:59:01 +0100 Subject: [PATCH] ConfigParser: Added the ability to not wrap exception messages for ConfigParser Both AgendaParser and ConfigParsers wrap exceptions with a a message saying what source of configuration caused the exception. AgendaParser uses ConfigParser within its load method, this leads to the "Error in foo" message appearing twice. This lets AgendaParser turn of the wrapping in ConfigParser --- wlauto/core/configuration/parsers.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/wlauto/core/configuration/parsers.py b/wlauto/core/configuration/parsers.py index 7d53424f..aa1dccda 100644 --- a/wlauto/core/configuration/parsers.py +++ b/wlauto/core/configuration/parsers.py @@ -167,7 +167,7 @@ class ConfigParser(object): def load_from_path(self, filepath): self.load(_load_file(filepath, "Config"), filepath) - def load(self, raw, source): # pylint: disable=too-many-branches + def load(self, raw, source, wrap_exceptions=True): # pylint: disable=too-many-branches try: if 'run_name' in raw: msg = '"run_name" can only be specified in the config section of an agenda' @@ -201,7 +201,10 @@ class ConfigParser(object): self.plugin_cache.add_configs(name, values, source) except ConfigError as e: - raise ConfigError('Error in "{}":\n{}'.format(source, str(e))) + if wrap_exceptions: + raise ConfigError('Error in "{}":\n{}'.format(source, str(e))) + else: + raise e class AgendaParser(object): @@ -230,7 +233,7 @@ class AgendaParser(object): self.run_config.set('run_name', entry.pop('run_name')) config_parser = ConfigParser(self.wa_config, self.run_config, self.jobs_config, self.plugin_cache) - config_parser.load(entry, source) + config_parser.load(entry, source, wrap_exceptions=False) # PHASE 2: Getting "section" and "workload" entries. sections = raw.pop("sections", [])