fix(gateway): handle wmic encoding errors on Windows non-English locales#17252
Closed
Kailigithub wants to merge 1 commit into
Closed
fix(gateway): handle wmic encoding errors on Windows non-English locales#17252Kailigithub wants to merge 1 commit into
Kailigithub wants to merge 1 commit into
Conversation
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 NousResearch#17049.
Collaborator
3 tasks
Contributor
|
Merged via #17435 (#17435) alongside @briandevans's companion fix for the same bug in |
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
UnicodeDecodeErrorand cascadingAttributeErrorin Windows gateway process scanning on non-English locales.Problem
On Windows systems with non-English locales,
wmicoutputs text in the system code page (e.g.cp936for Chinese,cp1252for Western European) rather than UTF-8. When Python'ssubprocess.rundecodes the output as UTF-8, aUnicodeDecodeErroris raised in the reader thread, causingresult.stdoutto becomeNone. This produces two cascading failures:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 8177in the subprocess reader threadAttributeError: 'NoneType' object has no attribute 'split'in_scan_gateway_pidsFix
encoding='utf-8'anderrors='ignore'explicitly tosubprocess.runso undecodable bytes are silently skipped rather than raisingNoneguard onresult.stdoutbefore calling.split()so the function returns an empty list cleanly instead of crashingTesting
python3 -m py_compile hermes_cli/gateway.pypasseswmicpath — the fix is defensive and non-breaking (addingencoding/errorstosubprocess.runwith non-Windows platforms has no effect; theNoneguard is a safe idempotent check)Closes #17049.