From 7bb8e6b63f76f2208feb121d35ea2b0df6defd57 Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Wed, 20 Mar 2024 16:36:43 +0100 Subject: [PATCH] fix(agent): Improve error logging in scan_plugins - Improve error logging in scan_plugins - Use importlib in scan_plugins rather than __import__ magic function --- autogpts/autogpt/autogpt/plugins/__init__.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/autogpts/autogpt/autogpt/plugins/__init__.py b/autogpts/autogpt/autogpt/plugins/__init__.py index 0b08a62e47b3..0bd52fc1aca8 100644 --- a/autogpts/autogpt/autogpt/plugins/__init__.py +++ b/autogpts/autogpt/autogpt/plugins/__init__.py @@ -230,11 +230,12 @@ def scan_plugins(config: Config) -> List[AutoGPTPluginTemplate]: qualified_module_name = ".".join(plugin_module_path) try: - __import__(qualified_module_name) - except ImportError: - logger.error(f"Failed to load {qualified_module_name}") + plugin = importlib.import_module(qualified_module_name) + except ImportError as e: + logger.error( + f"Failed to load {qualified_module_name} from {plugin_path}: {e}" + ) continue - plugin = sys.modules[qualified_module_name] if not plugins_config.is_enabled(plugin_module_name): logger.warning( @@ -261,8 +262,8 @@ def scan_plugins(config: Config) -> List[AutoGPTPluginTemplate]: zipped_package = zipimporter(str(plugin)) try: zipped_module = zipped_package.load_module(str(module.parent)) - except ZipImportError: - logger.error(f"Failed to load {str(module.parent)}") + except ZipImportError as e: + logger.error(f"Failed to load {module.parent} from {plugin}: {e}") continue for key in dir(zipped_module):