From 5e5e1c43a179e678b8ae5614788763dc5eae0e83 Mon Sep 17 00:00:00 2001 From: Patrick Robertson Date: Thu, 20 Mar 2025 18:09:26 +0400 Subject: [PATCH] When loading modules, check they have been added to the right 'step' in the config Fixes an issue seen on discord where a user accidentally set up metadata_enricher under 'extractors' --- src/auto_archiver/core/module.py | 6 +++++- src/auto_archiver/core/orchestrator.py | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/auto_archiver/core/module.py b/src/auto_archiver/core/module.py index 903a4ab..c263d95 100644 --- a/src/auto_archiver/core/module.py +++ b/src/auto_archiver/core/module.py @@ -85,7 +85,11 @@ class ModuleFactory: if not available: message = f"Module '{module_name}' not found. Are you sure it's installed/exists?" if "archiver" in module_name: - message += f" Did you mean {module_name.replace('archiver', 'extractor')}?" + message += f" Did you mean '{module_name.replace('archiver', 'extractor')}'?" + elif "gsheet" in module_name: + message += " Did you mean 'gsheet_feeder_db'?" + elif "atlos" in module_name: + message += " Did you mean 'atlos_feeder_db_storage'?" raise IndexError(message) return available[0] diff --git a/src/auto_archiver/core/orchestrator.py b/src/auto_archiver/core/orchestrator.py index d06c287..cbd1af5 100644 --- a/src/auto_archiver/core/orchestrator.py +++ b/src/auto_archiver/core/orchestrator.py @@ -373,9 +373,17 @@ Here's how that would look: \n\nsteps:\n extractors:\n - [your_extractor_name_ if module in invalid_modules: continue + # check to make sure that we're trying to load it as the correct type - i.e. make sure the user hasn't put it under the wrong 'step' + lazy_module: LazyBaseModule = self.module_factory.get_module_lazy(module) + if module_type not in lazy_module.type: + types = ",".join(f"'{t}'" for t in lazy_module.type) + raise SetupError( + f"Configuration Error: Module '{module}' is not a {module_type}, but has the types: {types}. Please check you set this module up under the right step in your orchestration file." + ) + loaded_module = None try: - loaded_module: BaseModule = self.module_factory.get_module(module, self.config) + loaded_module: BaseModule = lazy_module.load(self.config) except (KeyboardInterrupt, Exception) as e: if not isinstance(e, KeyboardInterrupt) and not isinstance(e, SetupError): logger.error(f"Error during setup of modules: {e}\n{traceback.format_exc()}")