fix(cli): force UTF-8 stdio so cp1252 Windows shells don't crash on '↳'/'✓'#290
Merged
Conversation
…↳'/'✓' Closes #271. Windows shells (cmd.exe, default PowerShell) ship with a cp1252 code page. Rich falls back to its legacy Windows renderer which encodes through the active code page — the first non-ASCII glyph in the progress UI (e.g. `↳` printed by `_timed_step`) raises a UnicodeEncodeError and aborts the run mid-pipeline, leaving partial state behind. Reconfigure sys.stdout/sys.stderr to UTF-8 with errors="replace" at the top of `repowise.cli`, before any Rich Console is constructed downstream. errors="replace" means even a stream that genuinely can't render a glyph still writes a placeholder rather than crashing. Behavior on already-UTF-8 streams (Linux, macOS, Windows Terminal with WT_SESSION) is unchanged.
swati510
approved these changes
May 28, 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.
Closes #271.
Summary
On Windows shells defaulting to cp1252 (
cmd.exe, default PowerShell sessions without WT_SESSION), Rich falls back to its legacy Windows renderer which encodes every printed line through the active code page. The first non-ASCII glyph in repowise's progress UI —↳in_timed_step,✓in the sub-step ticks — raisesUnicodeEncodeError: 'charmap' codec can't encode character '↳'and aborts the run mid-pipeline. Partial state has already been written by the time it triggers, so recovery depends on--resumeworking.The fix reconfigures
sys.stdoutandsys.stderrto UTF-8 witherrors="replace"at the top ofrepowise.cli, before any RichConsoleis constructed downstream.errors="replace"means even a stream that genuinely can't render a glyph still writes a placeholder rather than crashing, so the pipeline always reaches completion. Streams that are already UTF-8 (Linux, macOS, Windows Terminal with WT_SESSION) are unaffected.Adopted the reporter's suggested fix (option 1) — cheapest, broad-stroke, doesn't touch Rich internals.
Implementation notes
repowise/cli/_stdio.pyexposes_ensure_utf8_stdio(), called fromrepowise/cli/__init__.pyso it runs on any CLI import path.reconfiguremethod (e.g.pytest -s, embedding harnesses that pass aStringIO) and silent onOSError/ValueErrorfrom detached or non-text wrappers — the goal is never to introduce a crash while fixing one.Test plan
7 new tests in
tests/unit/cli/test_stdio.py:_reconfigurepassesencoding="utf-8", errors="replace"to the streamreconfiguremethod (StringIO)OSErrorfrom detached streamsNonestream_ensure_utf8_stdiodoesn't raise when both stdout/stderr are swappedStringIO_ensure_utf8_stdioreconfigures both stdout and stderrTextIOWrapperwitherrors="replace"accepts the exact↳ … ✓line from the bug report without raisingruff format+ruff checkclean on the changed files.Why not the other suggested fixes
The reporter listed three other options. Skipped because:
consoleinhelpers.py; any other module that constructs its ownConsole()would still hit the same trap. Reconfiguring stdio fixes them all at once.↳/✓) — would have to be applied at every print site, and Windows Terminal users would lose the nicer glyphs unnecessarily.