Mercurial > libervia-backend
changeset 751:1def5b7edf9f
core, bridge: better GenericException handling
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 17 Dec 2013 00:56:39 +0100 (2013-12-16) |
parents | c8b9f675ac17 |
children | f49945d728de |
files | frontends/src/primitivus/profile_manager.py src/bridge/DBus.py src/bridge/bridge_constructor/dbus_core_template.py src/core/exceptions.py src/memory/memory.py src/plugins/plugin_misc_account.py |
diffstat | 6 files changed, 33 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/primitivus/profile_manager.py Mon Dec 16 17:49:54 2013 +0100 +++ b/frontends/src/primitivus/profile_manager.py Tue Dec 17 00:56:39 2013 +0100 @@ -77,11 +77,11 @@ def _profileCreationFailure(self, reason): self.host.removePopUp() - if reason=="CONFLICT": + if reason=="ConflictError": message=_("A profile with this name already exists") - elif reason=="CANCELED": + elif reason=="CancelError": message=_("Profile creation cancelled by backend") - elif reason=="DATABASE": + elif reason=="DATABASE": # FIXME: doesn't seem to exist ! message=_("Database error") else: message=_("Unknown reason (%s)") % reason
--- a/src/bridge/DBus.py Mon Dec 16 17:49:54 2013 +0100 +++ b/src/bridge/DBus.py Tue Dec 17 00:56:39 2013 +0100 @@ -56,8 +56,13 @@ class GenericException(dbus.DBusException): def __init__(self, twisted_error): super(GenericException, self).__init__() - mess = twisted_error.getErrorMessage() - self._dbus_error_name = const_ERROR_PREFIX + "." + (mess or str(twisted_error.__class__)) + try: + error_name = str(twisted_error.value().__class__.__name__) + # twisted_error.value is a 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 DbusObject(dbus.service.Object):
--- a/src/bridge/bridge_constructor/dbus_core_template.py Mon Dec 16 17:49:54 2013 +0100 +++ b/src/bridge/bridge_constructor/dbus_core_template.py Tue Dec 17 00:56:39 2013 +0100 @@ -56,8 +56,13 @@ class GenericException(dbus.DBusException): def __init__(self, twisted_error): super(GenericException, self).__init__() - mess = twisted_error.getErrorMessage() - self._dbus_error_name = const_ERROR_PREFIX + "." + (mess or str(twisted_error.__class__)) + try: + error_name = str(twisted_error.value().__class__.__name__) + # twisted_error.value is a 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 DbusObject(dbus.service.Object):
--- a/src/core/exceptions.py Mon Dec 16 17:49:54 2013 +0100 +++ b/src/core/exceptions.py Tue Dec 17 00:56:39 2013 +0100 @@ -57,6 +57,18 @@ pass +class ConflictError(Exception): + pass + + +class CancelError(Exception): + pass + + +class InternalError(Exception): + pass + + class BridgeInitError(Exception): pass
--- a/src/memory/memory.py Mon Dec 16 17:49:54 2013 +0100 +++ b/src/memory/memory.py Tue Dec 17 00:56:39 2013 +0100 @@ -164,9 +164,9 @@ """ if self.storage.hasProfile(profile): info(_('The profile name already exists')) - return defer.fail(Failure(u"CONFLICT")) + return defer.fail(Failure(exceptions.ConflictError)) if not self.host.trigger.point("ProfileCreation", profile): - return defer.fail(Failure(u"CANCEL")) + return defer.fail(Failure(exceptions.CancelError)) return self.storage.createProfile(profile) def deleteProfile(self, profile):
--- a/src/plugins/plugin_misc_account.py Mon Dec 16 17:49:54 2013 +0100 +++ b/src/plugins/plugin_misc_account.py Tue Dec 17 00:56:39 2013 +0100 @@ -79,7 +79,7 @@ self.deferred.callback(None) else: error(_(u"Can't register Prosody account (error code: %(code)d): %(message)s") % {'code': reason.value.exitCode, 'message': self.data}) - self.deferred.errback(Failure(u"INTERNAL")) + self.deferred.errback(Failure(exceptions.InternalError)) class MiscAccount(object): @@ -118,7 +118,7 @@ raise exceptions.DataError if profile.lower() in self.getConfig('reserved_list'): - return defer.fail(Failure(u'CONFLICT')) + return defer.fail(Failure(exceptions.ConflictError)) d = self.host.memory.asyncCreateProfile(profile) d.addCallback(self._profileRegistered, email, password, profile)