Repository navigation
fix(cli): don't crash on Windows consoles when printing status symbols - #180
Open
Sahilkumar-r wants to merge 1 commit into
Open
Sahilkumar-r wants to merge 1 commit into
Sahilkumar-r wants to merge 1 commit into
Conversation
cbh/cli.py's say() and scripts/setup_harness_mcp.py's status prints use ✓/✗/→/↺ characters. Windows consoles default to a legacy code page (cp1252) that can't encode them, so any cbh subcommand or setup_harness_mcp.py run (and the test suites that exercise them) crashed with UnicodeEncodeError instead of printing the status line. Catch the encode error and fall back to encoding with errors="replace" so the line still prints (with "?" in place of the symbol) instead of crashing. Reproduced the crash with `cbh triage`, `scripts/test_triage.py`, and `python -m unittest discover -s tests` on Windows (msys2 Python 3.12, cp1252 console) before the fix; all three run clean after it. Tests run: python -m unittest discover -s tests (52 passed, was 4 failed + 3 errored before this fix on the same Windows environment), and scripts/test_triage.py / scripts/test_scan_identifiers.py directly — all pass. AI assistance was used (Claude Code / Claude Sonnet 5) to find and fix this bug. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This branch has not been deployed
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.
Problem
cbh's sharedsay()helper (cbh/cli.py) and the status prints inscripts/setup_harness_mcp.pywrite ✓/✗/→/↺ characters straight tostdout. Windows consoles default to a legacy code page (cp1252), which
can't encode those characters, so any
cbhsubcommand (e.g.cbh triage <finding.md>), or a run ofsetup_harness_mcp.py, crashes withUnicodeEncodeErrorinstead of printing the status line.This also breaks the test suites that exercise that code on Windows:
before this fix,
python -m unittest discover -s testshad 3 errors(
UnicodeEncodeErrorfromtest_mcp_hackerone_harness.pydrivingsetup_harness_mcp.py) and 4 failures (test_mcp_json_config.pyassertions that never saw their expected output because the subprocess
being tested crashed first), and
scripts/test_triage.pycrashed outrighton its own final
print().Fix
Wrap the
print()call insay()(and add an equivalent_say()insetup_harness_mcp.py, which doesn't importcbh.cli) in atry/except UnicodeEncodeErrorthat re-encodes witherrors="replace"so the line still prints — with
?standing in for the symbol — insteadof crashing. Routed
scripts/test_triage.py's own finalprint()throughthe already-fixed
say()for the same reason.Testing
Ran on Windows (msys2 Python 3.12, cp1252 console):
python -m unittest discover -s tests— 52 passed, 0 failed, 0 errors(was 4 failed + 3 errored before this fix, on the same environment).
python scripts/test_triage.py— passes, exit code 0 (previously crashed).python scripts/test_scan_identifiers.py— unaffected, still passes.python scripts/scan_identifiers.pyover the full working tree — 0matches (leak-guard unaffected).
No automated lint/style tool is configured in this repo (per
CONTRIBUTING.md);py_compileon the three changed files passes.Disclosure
AI assistance (Claude Code, Claude Sonnet 5) was used to find this bug
while evaluating the repo, draft the fix, and run the tests above. I
reviewed the diff and the test output myself before opening this PR.
🤖 Generated with Claude Code