From 003204b6a58faad7bc937ba029a99204cfa417e1 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 27 Sep 2007 13:56:01 +0100 Subject: [PATCH] dbus.service: Don't assume that exceptions passed to asynchronous callbacks are the same as the pending exception (fd.o #12403, https://dev.laptop.org/ticket/3370) --- dbus/service.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dbus/service.py b/dbus/service.py index 21165c5..4f600fc 100644 --- a/dbus/service.py +++ b/dbus/service.py @@ -272,7 +272,16 @@ def _method_reply_error(connection, message, exception): else: name = 'org.freedesktop.DBus.Python.%s.%s' % (exception.__module__, exception.__class__.__name__) - contents = traceback.format_exc() + et, ev, etb = sys.exc_info() + if ev is exception: + # The exception was actually thrown, so we can get a traceback + contents = ''.join(traceback.format_exception(et, ev, etb)) + else: + # We don't have any traceback for it, e.g. + # async_err_cb(MyException('Failed to badger the mushroom')) + # see also https://bugs.freedesktop.org/show_bug.cgi?id=12403 + contents = ''.join(traceback.format_exception_only(exception.__class__, + exception)) reply = ErrorMessage(message, name, contents) connection.send_message(reply) -- 2.11.4.GIT