fix: guard float(os.getenv) against ValueError in gateway platform adapters - #17967
Closed
vominh1919 wants to merge 1 commit into
Closed
fix: guard float(os.getenv) against ValueError in gateway platform adapters#17967vominh1919 wants to merge 1 commit into
vominh1919 wants to merge 1 commit into
Conversation
…apters Several gateway platform adapters cast environment variables directly via float(os.getenv(...)) without try/except. If any env var is set to a non-numeric string (e.g., HERMES_TELEGRAM_TEXT_BATCH_DELAY_SECONDS= "abc"), the platform adapter crashes with ValueError during __init__, preventing the entire gateway from starting. Affected files and variables: - telegram.py: MEDIA_BATCH_DELAY_SECONDS, TEXT_BATCH_DELAY_SECONDS, TEXT_BATCH_SPLIT_DELAY_SECONDS (3 instances) - discord.py: TEXT_BATCH_DELAY_SECONDS, TEXT_BATCH_SPLIT_DELAY_SECONDS (2 instances) - wecom.py: TEXT_BATCH_DELAY_SECONDS, TEXT_BATCH_SPLIT_DELAY_SECONDS (2 instances) Each call is now wrapped in try/except (ValueError, TypeError) with the original default value as fallback. Note: telegram.py already has a _env_float() helper (line 776) with this exact pattern, but it was not used in __init__. This fix makes the __init__ paths consistent with that helper.
Collaborator
Collaborator
|
Likely duplicate of #17905 (merged) — same root cause: unguarded float() env var casts in gateway platform adapters. |
2 tasks
Contributor
|
Thanks for the defensive gateway hardening. This is already implemented on current
The earlier discussion linked #17905; current adapter coverage is independently present in the later broader safeguard above. Automated hermes-sweeper review. |
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.
Problem
Several gateway platform adapters cast environment variables directly via
float(os.getenv(...))withouttry/except. If any env var is set to a non-numeric string (e.g.,HERMES_TELEGRAM_TEXT_BATCH_DELAY_SECONDS=abc), the platform adapter crashes withValueErrorduring__init__, preventing the entire gateway from starting.Affected files and variables:
telegram.py:MEDIA_BATCH_DELAY_SECONDS,TEXT_BATCH_DELAY_SECONDS,TEXT_BATCH_SPLIT_DELAY_SECONDS(3 instances)discord.py:TEXT_BATCH_DELAY_SECONDS,TEXT_BATCH_SPLIT_DELAY_SECONDS(2 instances)wecom.py:TEXT_BATCH_DELAY_SECONDS,TEXT_BATCH_SPLIT_DELAY_SECONDS(2 instances)Note:
telegram.pyalready has a_env_float()helper (line 776) with propertry/excepthandling, but it was not used in__init__.Fix
Each
float(os.getenv(...))call is wrapped intry/except (ValueError, TypeError)with the original default value as fallback.Diff: +28 lines, -7 lines across 3 files
Before vs After
ValueErrorcrash → gateway won't startTypeErrorcrashImpact