Skip to content

Commit

Permalink
fix(agent): Improve error logging in scan_plugins
Browse files Browse the repository at this point in the history
- Improve error logging in scan_plugins
- Use importlib in scan_plugins rather than __import__ magic function
  • Loading branch information
Pwuts committed Mar 20, 2024
1 parent b7a3cbf commit 7bb8e6b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions autogpts/autogpt/autogpt/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 235 in autogpts/autogpt/autogpt/plugins/__init__.py

View check run for this annotation

Codecov / codecov/patch

autogpts/autogpt/autogpt/plugins/__init__.py#L234-L235

Added lines #L234 - L235 were not covered by tests
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(
Expand All @@ -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}")

Check warning on line 266 in autogpts/autogpt/autogpt/plugins/__init__.py

View check run for this annotation

Codecov / codecov/patch

autogpts/autogpt/autogpt/plugins/__init__.py#L265-L266

Added lines #L265 - L266 were not covered by tests
continue

for key in dir(zipped_module):
Expand Down

0 comments on commit 7bb8e6b

Please # to comment.