From 147b5793fd9a3c2fd67a716d64f8cb2ed1496e39 Mon Sep 17 00:00:00 2001 From: drebs Date: Wed, 25 Mar 2015 17:30:23 -0300 Subject: [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. --- client/src/leap/soledad/client/api.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'client/src/leap/soledad') 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() -- cgit v1.2.3