fix(gateway): handle wmic UnicodeDecodeError gracefully#17073
Closed
liuhao1024 wants to merge 1 commit into
Closed
fix(gateway): handle wmic UnicodeDecodeError gracefully#17073liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
On Windows with non-English locales, wmic output uses system code page (e.g., cp936, cp1252) instead of UTF-8. When subprocess.run with text=True tries to decode as UTF-8, it raises UnicodeDecodeError and result.stdout becomes None, causing AttributeError in the next line. Fixes: - Add explicit encoding='utf-8' to wmic subprocess.run call - Add errors='ignore' to skip undecodable bytes instead of crashing - Check result.stdout is None before splitting to avoid AttributeError Adds regression test for decode error scenario. Fixes NousResearch#17049
Collaborator
Contributor
Author
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
Fixes UnicodeDecodeError crash in Windows gateway process scanning by adding explicit encoding and error handling to the wmic subprocess.run call.
Root Cause
On Windows systems, especially with non-English locales, the
wmiccommand outputs text in the system's code page (e.g., cp936 for Chinese, cp1252 for Western European), not UTF-8.The current code in
hermes_cli/gateway.py(lines 278-283) callssubprocess.runwithtext=True, which implicitly uses UTF-8 encoding. When wmic output contains non-UTF-8 bytes:result.stdoutbecomesNoneafter decode failureAttributeError: 'NoneType' object has no attribute 'split'Fix
encoding='utf-8'to subprocess.run callerrors='ignore'to skip undecodable bytes instead of crashingresult.stdout is Nonebefore splitting to avoid AttributeErrorThis allows the setup wizard to continue gracefully on systems where wmic output cannot be fully decoded, returning an empty PID list instead of crashing.
Testing
TestScanGatewayPids::test_handles_wmic_unicode_decode_error_gracefullythat simulates decode failure (stdout=None) and verifies empty list is returnedtest_find_gateway_pids_falls_back_to_pid_file_when_process_scan_failsstill passesImpact
hermes setupon Windows with non-English localesFixes #17049