From a060f26aa836dbe12bfd06365adbffd3cc9b7070 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Wed, 3 Nov 2004 22:58:20 +0000 Subject: [PATCH] Fixed bug #1059544, InvalidRegistryValues can now show what the name of the registry value is. --- scripts/supybot | 13 ++++++++++++- src/registry.py | 15 +++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/scripts/supybot b/scripts/supybot index 627ebd342..5461c799a 100755 --- a/scripts/supybot +++ b/scripts/supybot @@ -206,7 +206,18 @@ if __name__ == '__main__': sys.stderr.write(os.linesep) sys.exit(-1) - import supybot.log as log + try: + import supybot.log as log + except supybot.registry.InvalidRegistryValue, e: + # This is raised here because supybot.log imports supybot.conf. + name = e.value._name + errmsg = textwrap.fill('%s: %s' % (name, e), + width=78, subsequent_indent=' '*len(name)) + sys.stderr.write(errmsg) + sys.stderr.write('\n') + sys.stderr.write('Please fix this error in your configuration file ' + 'and restart your bot.\n') + sys.exit(-1) import supybot.conf as conf import supybot.world as world world.starting = True diff --git a/src/registry.py b/src/registry.py index 75d9fa5b8..a58a4eb3b 100644 --- a/src/registry.py +++ b/src/registry.py @@ -306,7 +306,9 @@ class Value(Group): else: s = """Invalid registry value. If you're getting this message, report it, because we forgot to put a proper help string here.""" - raise InvalidRegistryValue, utils.normalizeWhitespace(s) + e = InvalidRegistryValue(utils.normalizeWhitespace(s)) + e.value = self + raise e def setName(self, *args): if self._name == 'unset': @@ -445,9 +447,9 @@ class OnlySomeStrings(String): (self._help, utils.commaAndify(strings)) def error(self): - raise InvalidRegistryValue, \ - 'That is not a valid value. Valid values include %s.' % \ - utils.commaAndify(map(repr, self.validStrings)) + self.__parent.error('That is not a valid value. ' + 'Valid values include %s.' % \ + utils.commaAndify(map(repr, self.validStrings))) def normalize(self, s): lowered = s.lower() @@ -517,10 +519,11 @@ class Regexp(Value): kwargs['setDefault'] = False self.sr = '' self.value = None - super(Regexp, self).__init__(*args, **kwargs) + self.__parent = super(Regexp, self) + self.__parent.__init__(*args, **kwargs) def error(self, e): - raise InvalidRegistryValue, 'Value must be a regexp of the form %s' % e + self.__parent.error('Value must be a regexp of the form %s' % e) def set(self, s): try: