fix(gateway): replace assertions with proper error handling in Telegram and Feishu#6921
Closed
Cafexss wants to merge 1 commit into
Closed
Conversation
…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.
Contributor
|
Merged via PR #7123. Your commit was cherry-picked onto current main with your authorship preserved. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Python
assertstatements are stripped when running withpython -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 Noneguards araise last_error. In-Omode, the assert is skipped; iflast_erroris unexpectedlyNone,raise Noneproduces a confusingTypeError: exceptions must derive from BaseExceptioninstead of a meaningful error. Replaced with an explicitifcheck that raisesRuntimeError.feishu.py:975—_configure_with_overrides()usesassert original_configure is not Noneas a guard. While the outer scope only installs this closure whenoriginal_configure is not None, the assert silently disappears in optimized mode. Replaced with an explicitifcheck for defensive safety.Test plan
RuntimeErrorinstead ofTypeErrorpython -O— verify error paths still function correctly