Fixed bug #858008, and a fix for another bug that invalidCommands that raise an exception stop the whole process; now it'll continue to later plugins.

This commit is contained in:
Jeremy Fincher 2003-12-11 14:32:45 +00:00
parent 627dd87baf
commit 8f777db9f9
2 changed files with 37 additions and 1 deletions

View File

@ -327,7 +327,13 @@ class IrcObjectProxy:
if self.finished:
break
if hasattr(cb, 'invalidCommand'):
cb.invalidCommand(self, self.msg, self.args)
try:
cb.invalidCommand(self, self.msg, self.args)
except Exception, e:
cb.log.exception('Uncaught exception in invalidCommand:')
log.warning('Uncaught exception in %s.invalidCommand, '
'continuing to call other invalidCommands.' %
cb.name())
def finalEval(self):
assert not self.finalEvaled, 'finalEval called twice.'
@ -433,6 +439,7 @@ class IrcObjectProxy:
if len(s) < allowedLength:
self.irc.queueMsg(reply(msg, s, self.prefixName,
self.private,self.notice,self.to))
self.finished = True
return
msgs = textwrap.wrap(s, allowedLength-30) # -30 is for "nick:"
msgs.reverse()

View File

@ -323,6 +323,35 @@ class PrivmsgTestCase(ChannelPluginTestCase):
def testNoEscapingAttributeErrorFromTokenizeWithFirstElementList(self):
self.assertError('[plugin list] list')
class InvalidCommand(callbacks.Privmsg):
def invalidCommand(self, irc, msg, tokens):
irc.reply(msg, 'foo')
def testInvalidCommandOneReplyOnly(self):
try:
original = conf.replyWhenNotCommand
conf.replyWhenNotCommand = True
self.assertRegexp('asdfjkl', 'not a valid command')
self.irc.addCallback(self.InvalidCommand())
self.assertResponse('asdfjkl', 'foo')
self.assertNoResponse(' ', 2)
finally:
conf.replyWhenNotCommand = original
class BadInvalidCommand(callbacks.Privmsg):
def invalidCommand(self, irc, msg, tokens):
s = 'This shouldn\'t keep Misc.invalidCommand from being called'
raise Exception, s
def testBadInvalidCommandDoesNotKillAll(self):
try:
original = conf.replyWhenNotCommand
conf.replyWhenNotCommand = True
self.irc.addCallback(self.BadInvalidCommand())
self.assertRegexp('asdfjkl', 'not a valid command')
finally:
conf.replyWhenNotCommand = original
class PrivmsgCommandAndRegexpTestCase(PluginTestCase):
plugins = ('Utilities',) # Gotta put something.