Skip to content

fix: prevent UnicodeEncodeError crashes on legacy consoles (Windows cp1252) - #155

Open
vblearnstowritecode wants to merge 1 commit into
parallel-web:mainfrom
vblearnstowritecode:fix/windows-unicode-crash
Open

fix: prevent UnicodeEncodeError crashes on legacy consoles (Windows cp1252)#155
vblearnstowritecode wants to merge 1 commit into
parallel-web:mainfrom
vblearnstowritecode:fix/windows-unicode-crash

Conversation

@vblearnstowritecode

Copy link
Copy Markdown

Summary

Fixes #154

On Windows with legacy console code pages (e.g. cp1252), the CLI crashed with UnicodeEncodeError when printing output containing non-ASCII characters — notably parallel-cli search --help, whose --mode help text contains . Actual API commands worked, but any help/banner output with such characters was fatal.

Fix

Reconfigure stdout/stderr with errors="backslashreplace" at CLI import time (module level in commands.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.

before: UnicodeEncodeError: 'charmap' codec can't encode character '\u2192' ... [PYI-ERROR] Failed to execute script 'commands'
after:  ... one-shot \u2192 basic, agentic \u2192 advanced)  [default: basic]   <- help prints fine

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

  • Added regression test TestUnicodeSafeStreams::test_helper_replaces_unencodable_characters (wraps a cp1252 strict stream and verifies no crash + graceful replacement)
  • Reproduced crash before fix / verified help text prints after fix on Windows 11 cp1252 console
  • ruff check . and ruff format --check . clean on changed files
  • pytest tests/test_cli.py: 200 passed, 7 failed — all 7 failures are pre-existing on main in this environment (verified via git stash; unrelated to this change)

…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
@vblearnstowritecode
vblearnstowritecode requested a review from a team August 25, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI crashes with UnicodeEncodeError when printing help text on Windows (cp1252 console)

1 participant