fix: guard int(os.getenv()) casts against malformed env vars (#40598)
A non-numeric value in env vars like HERMES_STREAM_RETRIES, HERMES_KANBAN_SPECIFY_MAX_TOKENS, GOOGLE_CHAT_MAX_BYTES, IRC_PORT, etc. raised ValueError at import/init and crashed startup. Parse them safely, falling back to the default. Unified onto the existing utils.env_int(key, default) helper for core/ hermes_cli/tools modules instead of the original PR's three duplicate local helpers; plugins keep minimal inline guards (no core-utils import). All existing max()/min()/`or extra.get()` wrappers preserved. Co-authored-by: annguyenNous <annguyenNous@users.noreply.github.com>
This commit is contained in:
@@ -78,7 +78,10 @@ class FirecrawlBrowserProvider(BrowserProvider):
|
||||
}
|
||||
|
||||
def create_session(self, task_id: str) -> Dict[str, object]:
|
||||
ttl = int(os.environ.get("FIRECRAWL_BROWSER_TTL", "300"))
|
||||
try:
|
||||
ttl = int(os.environ.get("FIRECRAWL_BROWSER_TTL", "300"))
|
||||
except (ValueError, TypeError):
|
||||
ttl = 300
|
||||
|
||||
body: Dict[str, object] = {"ttl": ttl}
|
||||
|
||||
|
||||
@@ -540,8 +540,14 @@ class GoogleChatAdapter(BasePlatformAdapter):
|
||||
# they don't sit in the chat forever as "Hermes is thinking…".
|
||||
self._orphan_typing_messages: Dict[str, List[str]] = {}
|
||||
# FlowControl knobs (env-configurable).
|
||||
self._max_messages = int(os.getenv("GOOGLE_CHAT_MAX_MESSAGES", "1"))
|
||||
self._max_bytes = int(os.getenv("GOOGLE_CHAT_MAX_BYTES", str(16 * 1024 * 1024)))
|
||||
try:
|
||||
self._max_messages = int(os.getenv("GOOGLE_CHAT_MAX_MESSAGES", "1"))
|
||||
except (ValueError, TypeError):
|
||||
self._max_messages = 1
|
||||
try:
|
||||
self._max_bytes = int(os.getenv("GOOGLE_CHAT_MAX_BYTES", str(16 * 1024 * 1024)))
|
||||
except (ValueError, TypeError):
|
||||
self._max_bytes = 16 * 1024 * 1024
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Configuration loading and validation
|
||||
|
||||
@@ -107,7 +107,10 @@ class IRCAdapter(BasePlatformAdapter):
|
||||
|
||||
# Connection settings (env vars override config.yaml)
|
||||
self.server = os.getenv("IRC_SERVER") or extra.get("server", "")
|
||||
self.port = int(os.getenv("IRC_PORT") or extra.get("port", 6697))
|
||||
try:
|
||||
self.port = int(os.getenv("IRC_PORT") or extra.get("port", 6697))
|
||||
except (ValueError, TypeError):
|
||||
self.port = 6697
|
||||
self.nickname = os.getenv("IRC_NICKNAME") or extra.get("nickname", "hermes-bot")
|
||||
self.channel = os.getenv("IRC_CHANNEL") or extra.get("channel", "")
|
||||
self.use_tls = (
|
||||
|
||||
Reference in New Issue
Block a user