python-zulip-api icon indicating copy to clipboard operation
python-zulip-api copied to clipboard

bots: Fix error handling for bot not found.

Open showell opened this issue 7 years ago • 14 comments

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)

showell avatar Nov 30 '18 18:11 showell

@zulipbot claim

BhaskarJoshi-01 avatar Feb 22 '20 19:02 BhaskarJoshi-01

Welcome to Zulip, @BhaskarJoshi-01! We just sent you an invite to collaborate on this repository at https://github.com/zulip/python-zulip-api/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

Here's some tips to get you off to a good start:

As you work on this issue, you'll also want to refer to the Zulip code contribution guide, as well as the rest of the developer documentation on that site.

See you on the other side (that is, the pull request side)!

zulipbot avatar Feb 22 '20 19:02 zulipbot

Hello @BhaskarJoshi-01, you have been unassigned from this issue because you have not updated this issue or any referenced pull requests for over 14 days.

You can reclaim this issue or claim any other issue by commenting @zulipbot claim on that issue.

Thanks for your contributions, and hope to see you again soon!

zulipbot avatar Mar 03 '20 20:03 zulipbot

@zulipbot claim

arnavkohli avatar Mar 12 '20 14:03 arnavkohli

Welcome to Zulip, @arnavkohli! We just sent you an invite to collaborate on this repository at https://github.com/zulip/python-zulip-api/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

Here's some tips to get you off to a good start:

As you work on this issue, you'll also want to refer to the Zulip code contribution guide, as well as the rest of the developer documentation on that site.

See you on the other side (that is, the pull request side)!

zulipbot avatar Mar 12 '20 14:03 zulipbot

Hello @arnavkohli, you have been unassigned from this issue because you have not updated this issue or any referenced pull requests for over 14 days.

You can reclaim this issue or claim any other issue by commenting @zulipbot claim on that issue.

Thanks for your contributions, and hope to see you again soon!

zulipbot avatar Mar 24 '20 08:03 zulipbot

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)

Hello @showell , I want to contribute to this, but I am not clear about what the update should be. How do you think this can be improved to handle more testing?

mharyam avatar Nov 02 '21 20:11 mharyam

@zulipbot claim

vinitwadgaonkar avatar Dec 08 '21 14:12 vinitwadgaonkar

Hello @vinitwadgaonkar, you have been unassigned from this issue because you have not updated this issue or any referenced pull requests for over 14 days.

You can reclaim this issue or claim any other issue by commenting @zulipbot claim on that issue.

Thanks for your contributions, and hope to see you again soon!

zulipbot avatar Dec 18 '21 19:12 zulipbot