Mercurial > hg-stable
changeset 3073:24c1db20990c
Include section name and parameter name (if available) in config errors.
Added tests for this.
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 08 Sep 2006 10:01:45 +0200 |
parents | bc3fe3b5b785 |
children | be98c5ce4022 |
files | mercurial/ui.py tests/test-ui-config tests/test-ui-config.out |
diffstat | 3 files changed, 57 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/ui.py Fri Sep 08 09:36:18 2006 +0200 +++ b/mercurial/ui.py Fri Sep 08 10:01:45 2006 +0200 @@ -122,7 +122,9 @@ try: return self.cdata.get(section, name) except ConfigParser.InterpolationError, inst: - raise util.Abort(_("Error in configuration:\n%s") % inst) + raise util.Abort(_("Error in configuration section [%s] " + "parameter '%s':\n%s") + % (section, name, inst)) if self.parentui is None: return default else: @@ -144,7 +146,9 @@ try: return self.cdata.getboolean(section, name) except ConfigParser.InterpolationError, inst: - raise util.Abort(_("Error in configuration:\n%s") % inst) + raise util.Abort(_("Error in configuration section [%s] " + "parameter '%s':\n%s") + % (section, name, inst)) if self.parentui is None: return default else: @@ -162,7 +166,8 @@ try: items.update(dict(self.cdata.items(section))) except ConfigParser.InterpolationError, inst: - raise util.Abort(_("Error in configuration:\n%s") % inst) + raise util.Abort(_("Error in configuration section [%s]:\n%s") + % (section, inst)) x = items.items() x.sort() return x @@ -174,10 +179,14 @@ yield section, name, value seen[section, name] = 1 for section in self.cdata.sections(): - for name, value in self.cdata.items(section): - if (section, name) in seen: continue - yield section, name, value.replace('\n', '\\n') - seen[section, name] = 1 + try: + for name, value in self.cdata.items(section): + if (section, name) in seen: continue + yield section, name, value.replace('\n', '\\n') + seen[section, name] = 1 + except ConfigParser.InterpolationError, inst: + raise util.Abort(_("Error in configuration section [%s]:\n%s") + % (section, inst)) if self.parentui is not None: for parent in self.parentui.walkconfig(seen): yield parent
--- a/tests/test-ui-config Fri Sep 08 09:36:18 2006 +0200 +++ b/tests/test-ui-config Fri Sep 08 10:01:45 2006 +0200 @@ -1,6 +1,6 @@ #!/usr/bin/env python -from mercurial import ui +from mercurial import ui, util testui = ui.ui() testui.updateopts(config=[ @@ -11,10 +11,19 @@ 'lists.list2=foo bar baz', 'lists.list3=alice, bob', 'lists.list4=foo bar baz alice, bob', + 'interpolation.value1=hallo', + 'interpolation.value2=%(value1)s world', + 'interpolation.value3=%(novalue)s', + 'interpolation.value4=%(bad)1', + 'interpolation.value5=%bad2', ]) print repr(testui.configitems('values')) print repr(testui.configitems('lists')) +try: + print repr(testui.configitems('interpolation')) +except util.Abort, inst: + print inst print "---" print repr(testui.config('values', 'string')) print repr(testui.config('values', 'bool1')) @@ -45,3 +54,18 @@ print repr(testui.configlist('lists', 'unknown', ['foo bar'])) print repr(testui.configlist('lists', 'unknown', ['foo', 'bar'])) print "---" +print repr(testui.config('interpolation', 'value1')) +print repr(testui.config('interpolation', 'value2')) +try: + print repr(testui.config('interpolation', 'value3')) +except util.Abort, inst: + print inst +try: + print repr(testui.config('interpolation', 'value4')) +except util.Abort, inst: + print inst +try: + print repr(testui.config('interpolation', 'value5')) +except util.Abort, inst: + print inst +print "---"
--- a/tests/test-ui-config.out Fri Sep 08 09:36:18 2006 +0200 +++ b/tests/test-ui-config.out Fri Sep 08 10:01:45 2006 +0200 @@ -1,5 +1,7 @@ [('bool1', 'true'), ('bool2', 'false'), ('string', 'string value')] [('list1', 'foo'), ('list2', 'foo bar baz'), ('list3', 'alice, bob'), ('list4', 'foo bar baz alice, bob')] +Error in configuration section [interpolation]: +'%' must be followed by '%' or '(', found: '%bad2' --- 'string value' 'true' @@ -27,3 +29,17 @@ ['foo bar'] ['foo', 'bar'] --- +'hallo' +'hallo world' +Error in configuration section [interpolation] parameter 'value3': +Bad value substitution: + section: [interpolation] + option : value3 + key : novalue + rawval : + +Error in configuration section [interpolation] parameter 'value4': +bad interpolation variable reference '%(bad)1' +Error in configuration section [interpolation] parameter 'value5': +'%' must be followed by '%' or '(', found: '%bad2' +---