fix(browser): prevent UnicodeDecodeError on Windows with non-UTF-8 subprocess output - #50182
fix(browser): prevent UnicodeDecodeError on Windows with non-UTF-8 subprocess output#50182allin2 wants to merge 1 commit into
Conversation
…bprocess output
When agent-browser.cmd fails on Windows with a Chinese locale (GBK/CP936),
the error message from cmd.exe is encoded in the system default charset,
not UTF-8. Reading stderr with strict 'utf-8' codec raises:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 9
This masks the original error (e.g. 'node' not found) and makes all
browser_* tools unusable.
Fix by adding errors='replace' to the open() calls that read stdout/stderr
temp files. This replaces non-UTF-8 bytes with the U+FFFD replacement
character instead of crashing, so the actual subprocess error is visible
to users and agents.
Other open(encoding='utf-8') calls in this file are either already inside
try/except blocks (line 927) or read files guaranteed to be UTF-8
(/proc/1/cgroup, config files).
Closes: #<issue-number>
|
Duplicate of #47516 — same fix (adding |
|
Thanks for identifying the Windows locale failure. The strict UTF-8 reads are still present on current Problems
Suggested changes
Automated hermes-sweeper review. |
|
Closing as resolved by PR #70875 (merged, commit 0f732cb), which closed out this bug class codebase-wide: every |
Description
Fix
UnicodeDecodeErrorinbrowser_tool.pywhen running on Windows with Chinese locale (GBK/CP936).Problem
When
agent-browser.cmdfails on Windows with a Chinese locale, the error message fromcmd.exeis encoded in the system default charset (GBK), not UTF-8. Reading stderr with strictutf-8codec raises:This masks the original error (e.g., node not found) and makes all browser tools completely unusable on Windows Chinese systems.
Root Cause
In
_run_browser_command()(lines 2113-2116), stdout and stderr temp files are read withencoding="utf-8"without error handling:When
agent-browser.cmdfails (e.g., node not found),cmd.exeoutputs the error in GBK encoding. Byte0xB2at position 9 is not a valid UTF-8 start byte, triggeringUnicodeDecodeError.Fix
Add
errors="replace"to theopen()calls:This replaces non-UTF-8 bytes with the Unicode replacement character (U+FFFD) instead of crashing, so the actual subprocess error message is visible to users and agents.
Impact
Other open(encoding="utf-8") calls in this file