fix(gateway): add errors='replace' to subprocess.run for Windows wmic compatibility#17271
fix(gateway): add errors='replace' to subprocess.run for Windows wmic compatibility#17271zhanggttry wants to merge 3 commits into
Conversation
… compatibility Fixes NousResearch#17049 On Windows with non-UTF-8 locale (e.g. Chinese), wmic output contains non-UTF-8 bytes that cause UnicodeDecodeError when text=True is used. Replace text=True with encoding='utf-8', errors='replace' to handle this gracefully. Also add None guard for result.stdout as a defensive measure against decode failures causing stdout to be None.
Supply Chain Audit False PositiveThe Scan PR for critical supply chain risks check is a false positive for this PR. The scan script checks for patterns like - text=True,
+ encoding="utf-8",
+ errors="replace",The pattern match is likely triggered by the word There is no base64, no exec/eval, no hex-encoded strings, no .pth files — just standard This is the same false positive that affected other recent PRs (e.g. #17262, #17163). |
|
Closing in favor of #17435 (#17435), which ships the minimal |
Summary
Fixes #17049
On Windows with non-UTF-8 locale (e.g. Chinese/CJK), the
wmiccommand outputs text in the system's ANSI codepage, which may contain bytes that are invalid UTF-8. Whensubprocess.runis called withtext=True(which defaults toencoding='utf-8',errors='strict'), this causes aUnicodeDecodeErrorin the subprocess reader thread, and subsequently anAttributeErrorwhenresult.stdoutbecomesNone.Changes
In
_scan_gateway_pids()(hermes_cli/gateway.py):wmiccall: Replacetext=Truewithencoding="utf-8", errors="replace"so that non-UTF-8 bytes are replaced with U+FFFD instead of raisingUnicodeDecodeErrorpscall: Same change for consistency and defensive robustnessor result.stdout is Nonecheck before accessingresult.stdout.split(), preventingAttributeErrorif decode fails despiteerrors='replace'Test plan
_scan_gateway_pidstests continue to passBefore (broken)
After (fixed)