Skip to content

bots: Fix error handling for bot not found. #489

@showell

Description

@showell

The following logic in zulip_bots/zulip_bots/run.py can use some more testing. In particular, it's not clear the intent behind the provision check in the else block.

 84     result = finder.resolve_bot_path(args.bot)
 85     if result:
 86         bot_path, bot_name = result
 87         sys.path.insert(0, os.path.dirname(bot_path))
 88
 89         if args.provision:
 90             provision_bot(os.path.dirname(bot_path), args.force)
 91
 92         try:
 93             lib_module = finder.import_module_from_source(bot_path, bot_name)
 94         except ImportError as e:
 95             req_path = os.path.join(os.path.dirname(bot_path), "requirements.txt")
 96             with open(req_path) as fp:
 97                 deps_list = fp.read()
 98
 99             dep_err_msg = ("ERROR: The following dependencies for the {bot_name} bot are not installed:\n\n"
100                            "{deps_list}\n"
101                            "If you'd like us to install these dependencies, run:\n"
102                            "    zulip-run-bot {bot_name} --provision")
103             print(dep_err_msg.format(bot_name=bot_name, deps_list=deps_list))
104             sys.exit(1)
105     else:
106         lib_module = finder.import_module_by_name(args.bot)
107         if lib_module:
108             bot_name = lib_module.__name__
109             if args.provision:
110                 print("ERROR: Could not load bot's module for '{}'. Exiting now.")
111                 sys.exit(1)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions