Skip to content

fix(cli): don't crash on Windows consoles when printing status symbols - #180

Open
Sahilkumar-r wants to merge 1 commit into
elementalsouls:mainfrom
Sahilkumar-r:fix/windows-console-unicode-crash
Open

Sahilkumar-r wants to merge 1 commit into
elementalsouls:mainfrom
Sahilkumar-r:fix/windows-console-unicode-crash

Conversation

@Sahilkumar-r

@Sahilkumar-r Sahilkumar-r commented Nov 19, 2026 •

Copy link
Copy Markdown

Problem

cbh's shared say() helper (cbh/cli.py) and the status prints in
scripts/setup_harness_mcp.py write ✓/✗/→/↺ characters straight to
stdout. Windows consoles default to a legacy code page (cp1252), which
can't encode those characters, so any cbh subcommand (e.g. cbh triage <finding.md>), or a run of setup_harness_mcp.py, crashes with
UnicodeEncodeError instead 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 tests had 3 errors
(UnicodeEncodeError from test_mcp_hackerone_harness.py driving
setup_harness_mcp.py) and 4 failures (test_mcp_json_config.py
assertions that never saw their expected output because the subprocess
being tested crashed first), and scripts/test_triage.py crashed outright
on its own final print().

Fix

Wrap the print() call in say() (and add an equivalent _say() in
setup_harness_mcp.py, which doesn't import cbh.cli) in a
try/except UnicodeEncodeError that re-encodes with errors="replace"
so the line still prints — with ? standing in for the symbol — instead
of crashing. Routed scripts/test_triage.py's own final print() through
the 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.py over the full working tree — 0
    matches (leak-guard unaffected).

No automated lint/style tool is configured in this repo (per
CONTRIBUTING.md); py_compile on 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

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

No deployments
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.

1 participant