Skip to content

pr_review.py Crashes on Windows When It Prints a Reviewer's Emoji #2091

Closed

Description

@ptr727

Problem

On a Windows host, scripts/pr_review.py crashes with UnicodeEncodeError when it prints reviewer-authored text that holds a character outside the console's code page. Python's stdout on Windows falls back to the ANSI code page (cp1252 here) when PYTHONUTF8 and PYTHONIOENCODING are unset, and the script never reconfigures it. CodeRabbit's inline comments open with emoji category badges, so every reply to a CodeRabbit thread on Windows reaches this crash.

Nothing in CI exercises it, since every runner is Linux, where stdout is already UTF-8. GOVERNANCE.md "Supported Development Platforms" declares Windows supported.

Evidence

Windows 11, Python 3.13 (C:\Users\...\Python313), Git Bash, run from a hub checkout against ptr727/Blog PR 295 on 2026-09-29:

python scripts/pr_review.py reply 295 --repo ptr727/Blog --path sites/viljoen.family/site.js \
  --match "Scale the SVG stroke widths with the tree" --resolve --body "..."

Traceback (most recent call last):
  File "...\scripts\pr_review.py", line 3701, in <module>
    sys.exit(main())
  File "...\scripts\pr_review.py", line 3530, in main
    return reply_to_thread(owner, repo, a.number, a.match, a.body, a.path, a.resolve)
  File "...\scripts\pr_review.py", line 3201, in reply_to_thread
    print(f"answering: {describe(target)}")
  File "...\Lib\encodings\cp1252.py", line 19, in encode
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f3af' in position 62: character maps to <undefined>

The line numbers are from a checkout 35 commits behind main. On main at 2462619 the same statement is scripts/pr_review.py:3253, and there is still no reconfigure or PYTHONIOENCODING handling anywhere in the file. U+1F3AF is the first character of CodeRabbit's _🎯 Functional Correctness_ badge, which describe() prints as part of the thread's opening words.

Running the same command with PYTHONIOENCODING=utf-8 succeeded and printed status=REPLIED_AND_RESOLVED.

Reach

  • In reply, the crash comes before any write: describe() prints the reviewer's text at the answering: line before M_REPLY runs, and the lines printed after the reply and the resolve are the URL and json.dumps output, which is ASCII by default. The failed run posted nothing (the PR's review-comment count was unchanged), so a retry was safe. The unresolved: and candidate: lines, which print when --match finds no thread or several, go through describe() as well.
  • Any other path that prints reviewer-authored text, such as a quoted finding or a review-body excerpt in status or wait output, can crash the same way. A crash that comes after a write would report a failure for a write that succeeded, and a retry could then post a duplicate. I did not audit every print for that.

Suggested fix

At the start of main(), reconfigure both streams, for example sys.stdout.reconfigure(encoding="utf-8", errors="replace"), and the same for sys.stderr. That makes output independent of the host code page, like the encoding="utf-8" already pinned on the script's subprocess calls. A regression test can run the script's print path in a child with PYTHONIOENCODING=cp1252, the way scripts/tests/test_prose_lint.py already simulates a non-UTF-8 host.

#1577 is related but separate. It covers Python child processes that tests spawn, not this script's own console output.

Workaround until then: prefix each call with PYTHONIOENCODING=utf-8.

Activity

  1. added
    bug
    script
    on Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugscript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions