fix(cli): prevent UnicodeEncodeError in doctor on GBK consoles - #11731
Closed
konsisumer wants to merge 1 commit into
Closed
konsisumer wants to merge 1 commit into
konsisumer wants to merge 1 commit into
Conversation
…GBK consoles `hermes doctor` prints emoji (🩺, 🎉) and box-drawing characters on every run. On Windows consoles whose default encoding is not UTF-8 (GBK on zh-CN systems, cp1252 elsewhere), emitting 🩺 raises UnicodeEncodeError and the command aborts before running any check. Reconfigure sys.stdout/sys.stderr with errors='replace' (and switch to UTF-8 where the current encoding can't handle emoji) at the top of run_doctor. Unencodable chars become '?' instead of crashing, so the diagnostic output still works on legacy Windows consoles. Fixes NousResearch#7537.
This was referenced Apr 21, 2026
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
hermes doctorprints emoji (🩺, 🎉) and box-drawing chars on every run. On Windows consoles whose default encoding isn't UTF-8 (GBK on zh-CN, cp1252 elsewhere), the very first emoji raisesUnicodeEncodeError: 'gbk' codec can't encode character '\U0001fa7a'and the command aborts before any check runs.run_doctor, reconfiguresys.stdout/sys.stderrwitherrors='replace'— and switch to UTF-8 when the current encoding can't handle emoji. Unencodable characters become?instead of crashing, so diagnostic output still works on legacy Windows consoles.reconfigure(e.g. a redirectedStringIO) and reconfigure failures are silently ignored, so the helper is safe under capture.Fixes #7537.
Test plan
TestStdoutUnicodeSafetyunit tests cover: non-UTF-8 stream is reconfigured toutf-8+errors='replace'; UTF-8 stream only getserrors='replace'; streams withoutreconfigureare skipped;reconfigurefailures are swallowed.tests/hermes_cli/test_doctor.pypass (21 existing + 4 new), validated in a Docker container (python:3.12-slim).