diff --git a/sos/collector/__init__.py b/sos/collector/__init__.py index 6c6280401f..ae316755eb 100644 --- a/sos/collector/__init__.py +++ b/sos/collector/__init__.py @@ -237,7 +237,12 @@ def _find_modules_in_path(cls, path, modulename): def _import_modules(self, modname): """Import and return all found classes in a module""" mod_short_name = modname.split('.')[2] - module = __import__(modname, globals(), locals(), [mod_short_name]) + try: + module = __import__(modname, globals(), locals(), [mod_short_name]) + except ImportError as e: + print(f'Error while trying to load module {modname}: ' + f' {e.__class__.__name__}') + raise e modules = inspect.getmembers(module, inspect.isclass) for mod in modules: if mod[0] in ('SosHost', 'Cluster'): diff --git a/sos/utilities.py b/sos/utilities.py index d56afe28cf..ce371b0a03 100644 --- a/sos/utilities.py +++ b/sos/utilities.py @@ -308,7 +308,12 @@ def import_module(module_fqname, superclasses=None): be subclasses of the specified superclass or superclasses. If superclasses is plural it must be a tuple of classes.""" module_name = module_fqname.rpartition(".")[-1] - module = __import__(module_fqname, globals(), locals(), [module_name]) + try: + module = __import__(module_fqname, globals(), locals(), [module_name]) + except ImportError as e: + print(f'Error while trying to load module {module_fqname}: ' + f' {e.__class__.__name__}') + raise e modules = [class_ for cname, class_ in inspect.getmembers(module, inspect.isclass) if class_.__module__ == module_fqname]