From 1914322fda2b4318264742c4b18562486ffbf53d Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 7 Feb 2022 01:47:38 +0100 Subject: [PATCH] FIX: get_plugin methods should never swallow errors in case of failed initialization --- platypush/context/__init__.py | 4 +++- platypush/plugins/inspect/__init__.py | 3 ++- platypush/utils/__init__.py | 14 ++++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/platypush/context/__init__.py b/platypush/context/__init__.py index 16048fead..0f2a0239e 100644 --- a/platypush/context/__init__.py +++ b/platypush/context/__init__.py @@ -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 diff --git a/platypush/plugins/inspect/__init__.py b/platypush/plugins/inspect/__init__.py index e67ad13de..5271e82f6 100644 --- a/platypush/plugins/inspect/__init__.py +++ b/platypush/plugins/inspect/__init__.py @@ -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): diff --git a/platypush/utils/__init__.py b/platypush/utils/__init__.py index df0025479..c75615c85 100644 --- a/platypush/utils/__init__.py +++ b/platypush/utils/__init__.py @@ -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