Fix error shadowing in log when plugin fails to load

I didn't find a standard way of unwrapping the error,
short of printing an entire stack trace. I don't think printing
a stack trace in a log is useful, so I decided to print
the error.__cause__ explicitly.

Since there is always one single level of nesting in this code,
I think that's OK.

See https://docs.python.org/3/library/exceptions.html
pull/1467/head
Gonzalo Bulnes Guilpain 2024-02-08 22:06:59 -05:00
rodzic a1331d0b0b
commit 7c9b1da92a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: BF607641E5EC0039
1 zmienionych plików z 7 dodań i 4 usunięć

Wyświetl plik

@ -210,9 +210,12 @@ def get_plugins():
module = importlib.import_module("plugins.{}".format(dir))
plugin = (getattr(module, "Plugin"))()
except (ImportError, AttributeError):
module = importlib.import_module("coreplugins.{}".format(dir))
plugin = (getattr(module, "Plugin"))()
except (ImportError, AttributeError) as plugin_error:
try:
module = importlib.import_module("coreplugins.{}".format(dir))
plugin = (getattr(module, "Plugin"))()
except (ImportError, AttributeError) as coreplugin_error:
raise coreplugin_error from plugin_error
# Check version
manifest = plugin.get_manifest()
@ -237,7 +240,7 @@ def get_plugins():
plugins.append(plugin)
except Exception as e:
logger.warning("Failed to instantiate plugin {}: {}".format(dir, e))
logger.warning("Failed to instantiate plugin {}: {}: {}".format(dir, e, e.__cause__))
return plugins