Skip to content

run_bot: Improve the error when a bot module can't be found. - #933

Open
Hedger3 wants to merge 2 commits into
zulip:mainfrom
Hedger3:issue-636-bot-not-found
Open

Hedger3 wants to merge 2 commits into
zulip:mainfrom
Hedger3:issue-636-bot-not-found

Conversation

@Hedger3

@Hedger3 Hedger3 commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

This improves zulip-run-bot's error when it can't find a bot, which is what people hit in the chat threads linked from #636, and fixes a small bug in a nearby error message.

Fixes: Part of #636. The docs side is still open; #925 separately documents loading custom bots from files for the botserver.

Commit 1 fills in the bot name in the --provision error for bots run by module name, which printed a literal '{}':

ERROR: Could not load bot's module for '{}'. Exiting now.

Commit 2 makes the "Could not load bot module" error say where it looked and what to try.

Before:

ERROR: Could not load bot module. Exiting now.

After (bot at ~/mybot/mybot.py, run from another directory):

ERROR: Could not load bot module for "mybot". Looked for:
  - a file at /home/user/other/mybot
  - /home/user/python-zulip-api/zulip_bots/zulip_bots/bots/mybot/mybot.py (one of the bots included with zulip_bots)
  - a Python module named "mybot" that can be imported from PYTHONPATH

If you wrote this bot yourself, try passing the path to its .py file, e.g.:
    zulip-run-bot path/to/mybot.py --config-file ~/zuliprc

Exiting now.

With -r, there's a separate message, since only the registry is checked in that case.

I've left out changes to how bot modules are searched for, since that needs more discussion. I also didn't change the AttributeError: ... no attribute 'handler_class' you get when PYTHONPATH points at the folder containing the bot, which is another confusing case from the chat threads. I'm happy to look at that separately.

How did you test this PR?

Added tests in test_run.py for both changes, and checked that they fail without the fixes. Ran pytest zulip_bots (416 passed), and ruff check, ruff format --check and mypy on the changed files. I also reproduced the original error locally with a copy of helloworld at ~/mybot/mybot.py, and checked the new output shown above.

Self-review checklist
  • Self-reviewed the changes for clarity and maintainability
    (variable names, code reuse, readability, etc.).

Communicate decisions, questions, and potential concerns.

  • Explains differences from previous plans (e.g., issue description).
  • Highlights technical choices and bugs encountered.
  • Calls out remaining decisions and concerns.
  • Automated tests verify logic where appropriate.

Individual commits are ready for review (see commit discipline).

  • Each commit is a coherent idea.
  • Commit message(s) explain reasoning and motivation for changes.

Completed manual review and testing of the following:

  • Visual appearance of the changes.
  • Responsiveness and internationalization.
  • Strings and tooltips.
  • End-to-end functionality of buttons, interactions and flows.
  • Corner cases, error conditions, and easily imagined bugs.

When a bot is run by module name with --provision, the error message
printed a literal '{}' instead of the bot's name, since the string was
never formatted.
Previously, when zulip-run-bot couldn't find a bot, it only printed
"Could not load bot module", without saying what it had tried. This
was confusing for people running their own bots, who usually don't
know that a bare name is only looked up among the bundled bots and
then as an importable module.

The error now names the bot, lists the places that were checked, and
suggests passing the path to the bot's .py file. Registry lookups
(-r) get their own message.

Fixes part of zulip#636.
@Hedger3

Hedger3 commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator Author

The Debian 11 job fails while provisioning the server, with 404s from deb.debian.org for bullseye packages. That looks unrelated to this change, since bullseye has reached end of life and its packages have moved to the archive. The other jobs pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants