changeset 4281:9e63e02318ec

core: show warning instead of exception in case of missing dependency when loading plugins
author Goffi <goffi@goffi.org>
date Fri, 12 Jul 2024 18:53:00 +0200 (5 months ago)
parents 4cf98f506269
children 8da377040ba6
files libervia/backend/core/main.py
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/backend/core/main.py	Fri Jul 12 17:58:06 2024 +0200
+++ b/libervia/backend/core/main.py	Fri Jul 12 18:53:00 2024 +0200
@@ -384,7 +384,7 @@
             plugin_path = f"libervia.backend.plugins.{plug_name}"
             try:
                 __import__(plugin_path)
-            except exceptions.MissingModule as e:
+            except (ModuleNotFoundError, exceptions.MissingModule) as e:
                 self._unimport_plugin(plugin_path)
                 log.warning(
                     "Can't import plugin [{path}] because of an unavailale third party "
@@ -503,10 +503,17 @@
         # we instanciate the plugin here
         try:
             self.plugins[import_name] = getattr(mod, plugin_info["main"])(self)
-        except Exception as e:
-            log.exception(
-                f"Can't load plugin \"{plugin_info['name']}\", ignoring it: {e}"
-            )
+        except (exceptions.NotFound, Exception) as e:
+            if isinstance(e, exceptions.NotFound):
+                # A warning is enough for a missing dependency.
+                log.warning(
+                    f"Can't load plugin \"{plugin_info['name']}\", due to missing "
+                    f"dependency, ignoring it: {e}"
+                )
+            else:
+                log.exception(
+                    f"Can't load plugin \"{plugin_info['name']}\", ignoring it"
+                )
             if optional:
                 return
             raise ImportError("Error during initiation")