From e155907d219a93769a5a625baa0d425df689ff72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sun, 11 Aug 2024 11:06:12 +0200 Subject: [PATCH] Fix logging for failed load. --- src/proxy/proxypython.cpp | 2 +- src/runner/pythonrunner.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/proxy/proxypython.cpp b/src/proxy/proxypython.cpp index f8d244e..3e4ade4 100644 --- a/src/proxy/proxypython.cpp +++ b/src/proxy/proxypython.cpp @@ -121,7 +121,7 @@ QList> ProxyPython::load(const PluginExtension& extension) } if (extension.autodetect()) { - log::error("{}: automatic plugin detection is not supported for Python plugins", + log::debug("{}: automatic plugin detection is not supported for Python plugins", extension.metadata().name()); return {}; } diff --git a/src/runner/pythonrunner.cpp b/src/runner/pythonrunner.cpp index b959134..006214d 100644 --- a/src/runner/pythonrunner.cpp +++ b/src/runner/pythonrunner.cpp @@ -174,6 +174,13 @@ namespace mo2::python { // load the module auto spec = importlib_util.attr("spec_from_file_location")(name, pythonModule); + + if (Py_IsNone(spec.ptr())) { + MOBase::log::error("failed to load Python plugin '{}' from '{}'", + name, pythonModule); + return {}; + } + pymodule = importlib_util.attr("module_from_spec")(spec); sys.attr("modules")[py::str(name)] = pymodule; spec.attr("loader").attr("exec_module")(pymodule);