From 982bf3b2ecba86a76badf8cacbe82a8f5fc00b80 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Fri, 17 Dec 2010 23:33:13 +0800 Subject: RootStanza raises unexpected exceptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now raise the unexpected exceptions instead of sending them on the network. - avoids flood (sending a traceback on a MUC, for example…) and maybe some security issues. - lets you handle the traceback (catch it to handle it properly, or with except_hook, etc) - an exception cannot be raised without you knowing --- sleekxmpp/stanza/rootstanza.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/sleekxmpp/stanza/rootstanza.py b/sleekxmpp/stanza/rootstanza.py index 6975c72a..777314b9 100644 --- a/sleekxmpp/stanza/rootstanza.py +++ b/sleekxmpp/stanza/rootstanza.py @@ -54,16 +54,17 @@ class RootStanza(StanzaBase): e.extension_args) self['error'].append(extxml) self['error']['type'] = e.etype + self.send() else: - # We probably didn't raise this on purpose, so send a traceback + # We probably didn't raise this on purpose, so send an error stanza self['error']['condition'] = 'undefined-condition' - if sys.version_info < (3, 0): - self['error']['text'] = "SleekXMPP got into trouble." - else: - self['error']['text'] = traceback.format_tb(e.__traceback__) - log.exception('Error handling {%s}%s stanza' % - (self.namespace, self.name)) - self.send() - + self['error']['text'] = "SleekXMPP got into trouble." + self.send() + # log the error + log.exception('Error handling {%s}%s stanza' % + (self.namespace, self.name)) + # Finally raise the exception, so it can be handled (or not) + # at a higher level + raise e register_stanza_plugin(RootStanza, Error) -- cgit v1.2.3