summaryrefslogtreecommitdiff
path: root/client/src/leap/soledad
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2015-03-25 17:30:23 -0300
committerdrebs <drebs@leap.se>2015-04-23 17:46:18 -0300
commit147b5793fd9a3c2fd67a716d64f8cb2ed1496e39 (patch)
tree97ac0a84f3b3af05aa68f6bd4a65074ecc2745b2 /client/src/leap/soledad
parentb76f9b6c479d73206a6a29494b83d2b9c66b7a6a (diff)
[bug] fail gracefully when sync fails
With new soledad async api, we need to catch errors using errbacks instead of catching exceptions explicitelly. This commit fixed the api sync() call to intercept sync failures, log them, and do not propagate them down the callback chain.
Diffstat (limited to 'client/src/leap/soledad')
-rw-r--r--client/src/leap/soledad/client/api.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/client/src/leap/soledad/client/api.py b/client/src/leap/soledad/client/api.py
index b8409cbe..35b44ac8 100644
--- a/client/src/leap/soledad/client/api.py
+++ b/client/src/leap/soledad/client/api.py
@@ -44,6 +44,7 @@ from u1db.remote.ssl_match_hostname import match_hostname
from zope.interface import implements
from twisted.python import log
+from twisted.internet import defer
from leap.common.config import get_path_prefix
@@ -654,18 +655,20 @@ class Soledad(object):
return local_gen
sync_url = urlparse.urljoin(self._server_url, 'user-%s' % self.uuid)
- try:
- d = self._dbsyncer.sync(
- sync_url,
- creds=self._creds, autocreate=False,
- defer_decryption=defer_decryption)
-
- d.addCallbacks(on_sync_done, lambda err: log.err(err))
- return d
-
- # TODO catch the exception by adding an Errback
- except Exception as e:
- logger.error("Soledad exception when syncing: %s" % str(e))
+ d = self._dbsyncer.sync(
+ sync_url,
+ creds=self._creds, autocreate=False,
+ defer_decryption=defer_decryption)
+
+ # prevent sync failures from crashing the app by adding an errback
+ # that logs the failure and does not propagate it down the callback
+ # chain
+ def _errback(failure):
+ log.err(failure)
+ logger.error("Soledad exception when syncing: %s" % str(failure))
+
+ d.addCallbacks(on_sync_done, _errback)
+ return d
def stop_sync(self):
self._dbsyncer.stop_sync()