Skip to content

fix(gateway): replace assertions with proper error handling in Telegram and Feishu#6921

Closed
Cafexss wants to merge 1 commit into
NousResearch:mainfrom
Cafexss:fix/gateway-replace-assertions-with-error-handling
Closed

fix(gateway): replace assertions with proper error handling in Telegram and Feishu#6921
Cafexss wants to merge 1 commit into
NousResearch:mainfrom
Cafexss:fix/gateway-replace-assertions-with-error-handling

Conversation

@Cafexss

@Cafexss Cafexss commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Python assert statements are stripped when running with python -O (optimized mode), making them unsuitable for runtime control flow. Two locations in the gateway use assertions for error handling:

  • telegram_network.py:113 — After exhausting all fallback IPs, assert last_error is not None guards a raise last_error. In -O mode, the assert is skipped; if last_error is unexpectedly None, raise None produces a confusing TypeError: exceptions must derive from BaseException instead of a meaningful error. Replaced with an explicit if check that raises RuntimeError.

  • feishu.py:975_configure_with_overrides() uses assert original_configure is not None as a guard. While the outer scope only installs this closure when original_configure is not None, the assert silently disappears in optimized mode. Replaced with an explicit if check for defensive safety.

Test plan

  • Run Telegram adapter with all fallback IPs unreachable — verify clear RuntimeError instead of TypeError
  • Run Feishu adapter — verify WebSocket configure override works normally
  • Run with python -O — verify error paths still function correctly

…am and Feishu

Python assertions are stripped when running with `python -O` (optimized
mode), making them unsuitable for runtime error handling.

1. `telegram_network.py:113` — After exhausting all fallback IPs, the code
   uses `assert last_error is not None` before `raise last_error`. In
   optimized mode, the assert is skipped; if `last_error` is unexpectedly
   None, `raise None` produces a confusing `TypeError` instead of a
   meaningful error. Replace with an explicit `if` check that raises
   `RuntimeError` with a descriptive message.

2. `feishu.py:975` — The `_configure_with_overrides` closure uses
   `assert original_configure is not None` as a guard. While the outer
   scope only installs this closure when `original_configure` is not None,
   the assert would silently disappear in optimized mode. Replace with an
   explicit `if` check for defensive safety.
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #7123. Your commit was cherry-picked onto current main with your authorship preserved. Thanks!

@teknium1 teknium1 closed this Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants