sandbox-quantum / sandbox-quantum/switch

Mattermost `_find_existing_bot` swallows all exceptions and reports the bot as missing

Open Beginner friendly
#451 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
646
Forks
52
Avg merge
1d 7h
Merged PRs (30d)
151

Description

_find_existing_bot in core/switch_core/bridges/collaboration/mattermost/adapter.py (lines 1643-1663) wraps its entire paged lookup in except Exception: pass and returns None.

A session expiry, a 500 from Mattermost, a network blip or a malformed page all collapse into the same None. Both callers (lines 973 and 1125) read that as "this bot does not exist yet" and respond by creating the bot. The create then fails with a username-taken error, and the logs show "Failed to create Mattermost bot" — the real cause, that the lookup failed, is never recorded anywhere. Nothing is logged in the swallow itself.

This is a "Fail Loud, Never Fake" violation: an error path returns a plausible-looking value the caller cannot distinguish from a real answer.

Suggested fix

Remove the blanket handler and let the exception propagate — both call sites already have their own try/except with logger.exception around the create. At minimum, log the failure and re-raise.

Tests

No existing test references _find_existing_bot.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in core/switch_core/bridges/collaboration/mattermost/adapter.py at _find_existing_bot and inspect its callers at lines 973 and 1125. Add focused coverage for a lookup exception; done when lookup failures are no longer converted to None and the existing caller error handling can record the real failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.