bridge: async failures are more detailed (full class name + error message)
This commit is contained in:
parent
3d9795e578
commit
b9106c65d6
3 changed files with 69 additions and 25 deletions
|
|
@ -450,7 +450,7 @@ class DbusConstructor(Constructor):
|
|||
completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc)
|
||||
completion['async_args'] = 'callback=None, errback=None' if async else ''
|
||||
completion['async_comma'] = ', ' if async and function['sig_in'] else ''
|
||||
completion['async_args_result'] = 'reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:])' if async else ''
|
||||
completion['async_args_result'] = 'reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))' if async else ''
|
||||
result = "self.db_%(category)s_iface.%(name)s(%(args_result)s%(async_comma)s%(async_args_result)s)" % completion
|
||||
completion['result'] = ("unicode(%s)" if self.options.unicode and function['sig_out'] == 's' else "%s") % result
|
||||
methods_part.append("""\
|
||||
|
|
|
|||
|
|
@ -59,12 +59,13 @@ class GenericException(dbus.DBusException):
|
|||
def __init__(self, twisted_error):
|
||||
super(GenericException, self).__init__()
|
||||
try:
|
||||
error_name = str(twisted_error.value().__class__.__name__)
|
||||
# twisted_error.value is a class
|
||||
class_ = twisted_error.value().__class__
|
||||
except TypeError:
|
||||
# twisted_error.value is an instance
|
||||
error_name = str(twisted_error.value.__class__.__name__)
|
||||
self._dbus_error_name = const_ERROR_PREFIX + "." + error_name
|
||||
class_ = twisted_error.value.__class__
|
||||
self.args = (twisted_error.getErrorMessage(),)
|
||||
self._dbus_error_name = '.'.join([const_ERROR_PREFIX, class_.__module__, class_.__name__])
|
||||
|
||||
|
||||
class DbusObject(dbus.service.Object):
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from sat.core.i18n import _
|
||||
from bridge_frontend import BridgeFrontend
|
||||
from bridge_frontend import BridgeFrontend, BridgeException
|
||||
import dbus
|
||||
from sat.core.log import getLogger
|
||||
log = getLogger(__name__)
|
||||
|
|
@ -34,6 +34,16 @@ const_CORE_SUFFIX = ".core"
|
|||
const_PLUGIN_SUFFIX = ".plugin"
|
||||
|
||||
|
||||
def dbus_to_bridge_exception(dbus_e):
|
||||
"""Convert a DBusException to a BridgeException.
|
||||
|
||||
@param dbus_e (DBusException)
|
||||
@return: BridgeException
|
||||
"""
|
||||
name = dbus_e.get_dbus_name()[len(const_ERROR_PREFIX) + 1:]
|
||||
return BridgeException(name, dbus_e.get_dbus_message())
|
||||
|
||||
|
||||
class DBusBridgeFrontend(BridgeFrontend):
|
||||
def __init__(self):
|
||||
try:
|
||||
|
|
@ -91,7 +101,7 @@ class DBusBridgeFrontend(BridgeFrontend):
|
|||
|
||||
if async:
|
||||
kwargs['reply_handler'] = _callback
|
||||
kwargs['error_handler'] = lambda err: _errback(err._dbus_error_name[len(const_ERROR_PREFIX) + 1:])
|
||||
kwargs['error_handler'] = lambda err: _errback(dbus_to_bridge_exception(err))
|
||||
|
||||
return method(*args, **kwargs)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue