From f7d1fddbf32f0ca9a49ad8271b5d224f33998acb Mon Sep 17 00:00:00 2001 From: Kaili Date: Wed, 29 Apr 2026 03:51:24 +0000 Subject: [PATCH] fix(gateway): handle wmic encoding errors on Windows non-English locales On Windows systems with non-English locales, wmic outputs text in the system code page (e.g. cp936 for Chinese) rather than UTF-8. When Python decodes the output as UTF-8, a UnicodeDecodeError is raised in the subprocess reader thread, leaving result.stdout as None. This causes two cascading failures: - UnicodeDecodeError in the reader thread - AttributeError: 'NoneType' object has no attribute 'split' Fix by explicitly passing encoding='utf-8' and errors='ignore' to subprocess.run, and adding a None guard on result.stdout before splitting. Closes #17049. --- hermes_cli/gateway.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py index a3896b5bbd0e5..f5627a661f175 100644 --- a/hermes_cli/gateway.py +++ b/hermes_cli/gateway.py @@ -279,9 +279,11 @@ def _matches_current_profile(command: str) -> bool: ["wmic", "process", "get", "ProcessId,CommandLine", "/FORMAT:LIST"], capture_output=True, text=True, + encoding="utf-8", + errors="ignore", timeout=10, ) - if result.returncode != 0: + if result.returncode != 0 or result.stdout is None: return [] current_cmd = "" for line in result.stdout.split("\n"):