FIX: get_plugin methods should never swallow errors in case of failed initialization

This commit is contained in:
Fabio Manganiello 2022-02-07 01:47:38 +01:00
parent e4eb12fa6d
commit 1914322fda
Signed by: blacklight
GPG Key ID: D90FBA7F76362774
3 changed files with 13 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import logging
from threading import RLock
from ..bus import Bus
from ..config import Config
from ..utils import get_enabled_plugins
@ -129,8 +130,9 @@ def get_plugin(plugin_name, reload=False):
return plugins[plugin_name]
def get_bus():
def get_bus() -> Bus:
global main_bus
assert main_bus, 'The bus is not registered'
return main_bus

View File

@ -191,7 +191,8 @@ class InspectPlugin(Plugin):
try:
module = importlib.import_module(modname)
except Exception as e:
self.logger.debug(f'Could not import module {modname}: {str(e)}')
self.logger.warning(f'Could not import module {modname}')
self.logger.exception(e)
continue
for _, obj in inspect.getmembers(module):

View File

@ -248,11 +248,12 @@ def set_thread_name(name):
def find_bins_in_path(bin_name):
return [os.path.join(p, bin_name)
for p in os.environ.get('PATH', '').split(':')
if os.path.isfile(os.path.join(p, bin_name))
and (os.name == 'nt' or
os.access(os.path.join(p, bin_name), os.X_OK))]
return [
os.path.join(p, bin_name)
for p in os.environ.get('PATH', '').split(':')
if os.path.isfile(os.path.join(p, bin_name)) and (
os.name == 'nt' or os.access(os.path.join(p, bin_name), os.X_OK)
)]
def find_files_by_ext(directory, *exts):
@ -444,7 +445,8 @@ def get_enabled_plugins() -> dict:
if plugin:
plugins[name] = plugin
except Exception as e:
logger.debug(f'Could not get plugin {name}: {e}')
logger.warning(f'Could not initialize plugin {name}')
logger.exception(e)
return plugins