mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-22 10:29:25 +01:00
irclib: Catch exception from outFilter, as with inFilter
This commit is contained in:
parent
862fca1602
commit
088d0f54dd
@ -1527,7 +1527,11 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
|
||||
msg._len = msg._str = None
|
||||
for callback in reversed(self.callbacks):
|
||||
self._setMsgChannel(msg)
|
||||
msg = callback.outFilter(self, msg)
|
||||
try:
|
||||
msg = callback.outFilter(self, msg)
|
||||
except:
|
||||
log.exception('Uncaught exception in outFilter:')
|
||||
continue
|
||||
if msg is None:
|
||||
log.debug('%s.outFilter returned None.', callback.name())
|
||||
return self.takeMsg()
|
||||
|
@ -1023,6 +1023,46 @@ class IrcTestCase(SupyTestCase):
|
||||
self.irc.feedMsg(ircmsgs.IrcMsg('MODE @#linux3 +v foo'))
|
||||
self.assertEqual(self.irc.state.history[-1].channel, None)
|
||||
|
||||
def testFilterErrors(self):
|
||||
self.irc.reset()
|
||||
while self.irc.takeMsg() is not None:
|
||||
pass
|
||||
class BuggyCallback(irclib.IrcCallback):
|
||||
infilter_called = False
|
||||
outfilter_called = False
|
||||
def name(self):
|
||||
return 'buggycallback'
|
||||
def inFilter(self, irc, msg):
|
||||
self.infilter_called = True
|
||||
raise Exception('test exception')
|
||||
def outFilter(self, irc, msg):
|
||||
self.outfilter_called = True
|
||||
raise Exception('test exception')
|
||||
class Callback(irclib.IrcCallback):
|
||||
channels_set = None
|
||||
def name(self):
|
||||
return 'testcallback'
|
||||
def doCommand(self, irc, msg):
|
||||
irc.sendMsg(ircmsgs.privmsg('#foo', 'bar'))
|
||||
def inFilter(self, irc, msg):
|
||||
self.infilter_called = True
|
||||
raise Exception('test exception')
|
||||
def outFilter(self, irc, msg):
|
||||
self.outfilter_called = True
|
||||
raise Exception('test exception')
|
||||
|
||||
bc = BuggyCallback()
|
||||
self.irc.addCallback(bc)
|
||||
c = Callback()
|
||||
self.irc.addCallback(c)
|
||||
self.irc.feedMsg(ircmsgs.IrcMsg('COMMAND blah'))
|
||||
m = self.irc.takeMsg()
|
||||
self.assertEqual(m, ircmsgs.privmsg('#foo', 'bar'))
|
||||
self.assertTrue(bc.infilter_called)
|
||||
self.assertTrue(bc.outfilter_called)
|
||||
self.assertTrue(c.infilter_called)
|
||||
self.assertTrue(c.outfilter_called)
|
||||
|
||||
def testQuit(self):
|
||||
self.irc.reset()
|
||||
self.irc.feedMsg(ircmsgs.IrcMsg(':someuser JOIN #foo'))
|
||||
|
Loading…
Reference in New Issue
Block a user