fix: prevent UnicodeEncodeError crashes on legacy consoles (Windows cp1252) - #155
Open
vblearnstowritecode wants to merge 1 commit into
Open
Conversation
…p1252) Help text and banner output contain non-ASCII characters (arrows, box-drawing characters) that cannot be encoded on legacy code pages such as cp1252, causing the CLI to crash instead of printing output (e.g. 'parallel-cli search --help' on Windows). Reconfigure stdout/stderr with errors='backslashreplace' at CLI import time so unencodable characters degrade to escape sequences rather than raising UnicodeEncodeError. Unicode-capable terminals are unaffected. Fixes parallel-web#154
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 #154
On Windows with legacy console code pages (e.g. cp1252), the CLI crashed with
UnicodeEncodeErrorwhen printing output containing non-ASCII characters — notablyparallel-cli search --help, whose--modehelp text contains→. Actual API commands worked, but any help/banner output with such characters was fatal.Fix
Reconfigure
stdout/stderrwitherrors="backslashreplace"at CLI import time (module level incommands.py, since click prints help during argument parsing before any command callback runs). Unencodable characters now degrade to escape sequences (\u2192) instead of crashing. Unicode-capable terminals are completely unaffected.This also protects other non-ASCII CLI output (e.g. the box-drawing characters used by the ASCII banner) on legacy code pages.
Test plan
TestUnicodeSafeStreams::test_helper_replaces_unencodable_characters(wraps a cp1252 strict stream and verifies no crash + graceful replacement)ruff check .andruff format --check .clean on changed filespytest tests/test_cli.py: 200 passed, 7 failed — all 7 failures are pre-existing onmainin this environment (verified viagit stash; unrelated to this change)