changeset 859:0e9341e537d6

server: catch exceptions on service profile connection check, and show an helping message if an error is caught
author Goffi <goffi@goffi.org>
date Sun, 24 Jan 2016 20:06:06 +0100
parents 7dde76708892
children 05cd9dc775e6
files src/server/server.py
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/server/server.py	Sun Jan 24 19:00:56 2016 +0100
+++ b/src/server/server.py	Sun Jan 24 20:06:06 2016 +0100
@@ -1492,7 +1492,16 @@
             self.stop()
 
         def initOk(dummy):
-            if not self.bridge.isConnected(C.SERVICE_PROFILE):
+            try:
+                connected = self.bridge.isConnected(C.SERVICE_PROFILE)
+            except Exception as e:
+                # we don't want the traceback
+                msg = [l for l in unicode(e).split('\n') if l][-1]
+                log.error(u"Can't check service profile ({profile}), are you sure it exists ?\n{error}".format(
+                    profile=C.SERVICE_PROFILE, error=msg))
+                self.stop()
+                return
+            if not connected:
                 self.bridge.asyncConnect(C.SERVICE_PROFILE, self.options['passphrase'],
                                          callback=self._startService, errback=eb)
             else:
@@ -1608,7 +1617,10 @@
         log.info(_("launching cleaning methods"))
         for callback, args, kwargs in self._cleanup:
             callback(*args, **kwargs)
-        self.bridge.disconnect(C.SERVICE_PROFILE)
+        try:
+            self.bridge.disconnect(C.SERVICE_PROFILE)
+        except Exception:
+            log.warning(u"Can't disconnect service profile")
 
     def run(self):
         reactor.run()