changeset 3989:f5ba7594cced

core (main): log Exception when `bridge_pi` fails
author Goffi <goffi@goffi.org>
date Thu, 24 Nov 2022 12:25:04 +0100
parents 760f563b1243
children 3b72743b92db
files sat/core/sat_main.py tests/unit/conftest.py
diffstat 2 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/sat/core/sat_main.py	Thu Nov 24 10:08:47 2022 +0100
+++ b/sat/core/sat_main.py	Thu Nov 24 12:25:04 2022 +0100
@@ -95,10 +95,10 @@
         try:
             self.bridge = bridge_module.Bridge()
         except exceptions.BridgeInitError:
-            log.error("Bridge can't be initialised, can't start Libervia Backend")
+            log.exception("Bridge can't be initialised, can't start Libervia Backend")
             sys.exit(1)
 
-        defer.ensureDeferred(self._postInit())
+        defer.ensureDeferred(self._post_init())
 
     @property
     def version(self):
@@ -128,13 +128,19 @@
     def bridge_name(self):
         return os.path.splitext(os.path.basename(self.bridge.__file__))[0]
 
-    async def _postInit(self):
+    async def _post_init(self):
         try:
             bridge_pi = self.bridge.postInit
         except AttributeError:
             pass
         else:
-            await bridge_pi()
+            try:
+                await bridge_pi()
+            except Exception:
+                log.exception("Could not initialize bridge")
+                # because init is not complete at this stage, we use callLater
+                reactor.callLater(0, self.stop)
+                return
 
         self.bridge.register_method("getReady", lambda: self.initialised)
         self.bridge.register_method("getVersion", lambda: self.full_version)
--- a/tests/unit/conftest.py	Thu Nov 24 10:08:47 2022 +0100
+++ b/tests/unit/conftest.py	Thu Nov 24 12:25:04 2022 +0100
@@ -60,7 +60,7 @@
 
         self.trigger = trigger.TriggerManager()
         self.bridge = bridge
-        defer.ensureDeferred(self._postInit())
+        defer.ensureDeferred(self._post_init())
         self.common_cache = AsyncMock()
         self._import_plugins()
         self._addBaseMenus()
@@ -98,7 +98,7 @@
     def _init(self):
         pass
 
-    async def _postInit(self):
+    async def _post_init(self):
         pass