Skip to content

Commit ac6aa4e

Browse files
sebixaaronkaplan
authored andcommitted
bug: ctl: handle non-existing bot modules
the new function utils.get_bot_module_name returns None if a bot module does not exist, and importlib.import_module raises an exception when passed None
1 parent 76c08f9 commit ac6aa4e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

intelmq/bin/intelmqctl.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,12 @@ def check(self, no_connections=False, check_executables=True):
941941
check_logger.error('SyntaxError in bot %r: %r', bot_id, exc)
942942
retval = 1
943943
continue
944+
except AttributeError:
945+
# if module does not exist, utils.get_bot_module_name returns None. import_module then raises
946+
# AttributeError: 'NoneType' object has no attribute 'startswith'
947+
check_logger.error('Incomplete installation: Bot %r not importable.', bot_id,)
948+
retval = 1
949+
continue
944950
bot = getattr(bot_module, 'BOT')
945951
bot_parameters = copy.deepcopy(global_settings)
946952
bot_parameters.update(bot_config.get('parameters', {})) # the parameters field may not exist

intelmq/lib/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,10 @@ def _get_console_entry_points():
852852
return entries.get("console_scripts", []) # it's a dict
853853

854854

855-
def get_bot_module_name(bot_name: str) -> str:
855+
def get_bot_module_name(bot_name: str) -> Optional[str]:
856+
"""
857+
Returns None if the bot does not exist
858+
"""
856859
entries = entry_points()
857860
if hasattr(entries, "select"):
858861
entries = tuple(entries.select(name=bot_name, group="console_scripts"))

0 commit comments

Comments
 (0)