fix(gateway): add missing UTF-8 encoding to file I/O preventing crashes on Windows
On Windows, Python's open() defaults to the system locale encoding (e.g. cp1254 for Turkish, cp1252 for Western European) instead of UTF-8. The gateway already uses ensure_ascii=False in json.dumps() to preserve Unicode characters in chat messages, but the corresponding open() calls lack encoding="utf-8". This mismatch causes UnicodeEncodeError / UnicodeDecodeError when users send non-ASCII messages (Turkish, Japanese, Arabic, emoji, etc.) through Telegram, Discord, WhatsApp, or Slack on Windows. The project already fixed this for .env files in hermes_cli/config.py (line 624) but the gateway module was missed. Files fixed: - gateway/session.py: session index + JSONL transcript read/write (5 calls) - gateway/channel_directory.py: channel directory read/write (3 calls) - gateway/mirror.py: session index read + transcript append (2 calls)
This commit is contained in:
@@ -73,7 +73,7 @@ def _find_session_id(platform: str, chat_id: str) -> Optional[str]:
|
||||
return None
|
||||
|
||||
try:
|
||||
with open(_SESSIONS_INDEX) as f:
|
||||
with open(_SESSIONS_INDEX, encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
except Exception:
|
||||
return None
|
||||
@@ -103,7 +103,7 @@ def _append_to_jsonl(session_id: str, message: dict) -> None:
|
||||
"""Append a message to the JSONL transcript file."""
|
||||
transcript_path = _SESSIONS_DIR / f"{session_id}.jsonl"
|
||||
try:
|
||||
with open(transcript_path, "a") as f:
|
||||
with open(transcript_path, "a", encoding="utf-8") as f:
|
||||
f.write(json.dumps(message, ensure_ascii=False) + "\n")
|
||||
except Exception as e:
|
||||
logger.debug("Mirror JSONL write failed: %s", e)
|
||||
|
||||
Reference in New Issue
Block a user