Mercurial > p > roundup > code
diff roundup/configuration.py @ 6557:8687c096a945
Handle configparser.InterpolationSyntaxError
Under Python 3, an option value with a single % (e.g. this % is a
test) throws
configparser.InterpolationSyntaxError: '%' must be followed by
'%' or '(', found: '%s))'
Added code to capture this, raise a different exception. roundup-admin
handles the error and exits cleanly. Other code shows the traceback.
The new error message reports the file, section and option causing the
problem to allow easier repair.
Also updated roundup translations and added tests.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 13 Dec 2021 12:48:57 -0500 |
| parents | a036712c96f4 |
| children | c77bd76b57da |
line wrap: on
line diff
--- a/roundup/configuration.py Sun Dec 12 23:42:44 2021 -0500 +++ b/roundup/configuration.py Mon Dec 13 12:48:57 2021 -0500 @@ -31,14 +31,17 @@ from roundup.exceptions import RoundupException -# XXX i don't think this module needs string translation, does it? - ### Exceptions class ConfigurationError(RoundupException): pass +class ParsingOptionError(ConfigurationError): + def __str__(self): + _args = self.args + return self.args[0] + class NoConfigError(ConfigurationError): @@ -261,8 +264,17 @@ def load_ini(self, config): """Load value from ConfigParser object""" - if config.has_option(self.section, self.setting): - self.set(config.get(self.section, self.setting)) + try: + if config.has_option(self.section, self.setting): + self.set(config.get(self.section, self.setting)) + except configparser.InterpolationSyntaxError as e: + raise ParsingOptionError( + _("Error in %(filepath)s with section [%(section)s] at option %(option)s: %(message)s")%{ + "filepath": self.config.filepath, + "section": e.section, + "option": e.option, + "message": e.message}) + class BooleanOption(Option):
