From 5d0d1afcdf7cb8371e5f0bbfdfb8eb3feb2d095e Mon Sep 17 00:00:00 2001 From: annguyenNous Date: Sat, 13 Jun 2026 16:57:58 +0700 Subject: [PATCH] fix: guard float() env var casts in Discord adapter __init__ Two env var casts in Discord adapter __init__ use raw float() without try/except. If HERMES_DISCORD_TEXT_BATCH_DELAY_SECONDS or HERMES_DISCORD_TEXT_BATCH_SPLIT_DELAY_SECONDS is set to a non-numeric value, the entire Discord adapter fails to initialize. Other platform adapters (google_chat) already guard these with try/except (ValueError, TypeError). This applies the same pattern. --- plugins/platforms/discord/adapter.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.py index 196564dd14f95..3c178f1b3c528 100644 --- a/plugins/platforms/discord/adapter.py +++ b/plugins/platforms/discord/adapter.py @@ -628,8 +628,14 @@ def __init__(self, config: PlatformConfig): self._voice_clients: Dict[int, Any] = {} # guild_id -> VoiceClient self._voice_locks: Dict[int, asyncio.Lock] = {} # guild_id -> serialize join/leave # Text batching: merge rapid successive messages (Telegram-style) - self._text_batch_delay_seconds = float(os.getenv("HERMES_DISCORD_TEXT_BATCH_DELAY_SECONDS", "0.6")) - self._text_batch_split_delay_seconds = float(os.getenv("HERMES_DISCORD_TEXT_BATCH_SPLIT_DELAY_SECONDS", "2.0")) + try: + self._text_batch_delay_seconds = float(os.getenv("HERMES_DISCORD_TEXT_BATCH_DELAY_SECONDS", "0.6")) + except (ValueError, TypeError): + self._text_batch_delay_seconds = 0.6 + try: + self._text_batch_split_delay_seconds = float(os.getenv("HERMES_DISCORD_TEXT_BATCH_SPLIT_DELAY_SECONDS", "2.0")) + except (ValueError, TypeError): + self._text_batch_split_delay_seconds = 2.0 self._pending_text_batches: Dict[str, MessageEvent] = {} self._pending_text_batch_tasks: Dict[str, asyncio.Task] = {} self._voice_text_channels: Dict[int, int] = {} # guild_id -> text_channel_id