Skip to content

gbuffer_census, navmesh_tile_obj: guard stdout with errors='replace' - #7983

Closed
Friendships6666 wants to merge 1 commit into
ProjectLeonida:mainfrom
Friendships6666:guard-stdout-gbuffer-navmesh
Closed

Friendships6666 wants to merge 1 commit into
ProjectLeonida:mainfrom
Friendships6666:guard-stdout-gbuffer-navmesh

Conversation

@Friendships6666

Copy link
Copy Markdown
Contributor

Claim: #7694 (comment)
Depends on: none (the other nine entries of the list are separate pull requests; the list only turns fully green when all of them land)

What and why

tests/test_tool_stdout_encoding.py lists 11 programs whose __main__ block doesn't set errors="replace" on stdout. Nine of them already have an open pull request (#7032, #6508, #7152, #7184, #7174, #7650). These two were the rest:

  • tools/gbuffer_census.py:145 — prints the input paths it censused
  • tools/navmesh_tile_obj.py:75 — prints the --out path it wrote

On Windows a redirected stdout is encoded with the console's ANSI code page, and python -I ignores PYTHONUTF8/PYTHONIOENCODING, so either path with a character the code page lacks ended the run in UnicodeEncodeError.

The fix

The same four lines the converted tools use, in the same place and with the same comment:

    try:  # a redirected stdout is strict ANSI code page under -I; write '?' for what it cannot encode
        sys.stdout.reconfigure(errors="replace")
    except (AttributeError, ValueError, OSError):
        pass

AttributeError covers a stdout without reconfigure (a captured StringIO in a test), ValueError a closed one, OSError a detached console.

Tested

Linux, Python 3.14.8, no game files.

  • python3 -m pytest -q tests/test_tool_stdout_encoding.py → 3 passed, 2 subtests passed, 1 failed; the remaining failure is the whole-tree scan, whose list dropped from 11 to 9 entries and no longer names either file
  • python3 -I -X utf8=0 tests/test_tool_stdout_encoding.py → same result
  • python3 -I tools/gbuffer_census.py --help and python3 -I tools/navmesh_tile_obj.py --help → exit 0
  • compileall and git diff --check clean
  • not run on Windows, where the crash is; the guard's behaviour there is not exercised by the suite either way

Both print a caller path that the console code page may not have: gbuffer_census
its input, navmesh_tile_obj its --out. Under a redirected stdout and `python -I`
that is a strict UnicodeEncodeError on Windows, so a Polish, Greek or CJK user
name ended the run.

Same guard, wording and placement as the tools already converted, and the last
two entries of the test_tool_stdout_encoding list that no open pull request
covers.
@noviw-rblx

Copy link
Copy Markdown

checked: #7983 | with: python -I tests/test_tool_stdout_encoding.py | on: Windows 11, CPython 3.13, head f41d426, CPU only | result: the two files this PR touches (gbuffer_census.py, navmesh_tile_obj.py) now carry the sys.stdout.reconfigure(errors="replace") guard; both are no longer in the test's missing list (9 other files still missing, covered by their own PRs). compileall -q clean. No game data, no GPU.

@ps1ke

ps1ke commented Nov 23, 2026

Copy link
Copy Markdown

Tested f41d42611 on Linux x86-64 (Arch, Python 3.14), CPU only, no GPU, no game files: pass.

  • python -I tests/test_tool_stdout_encoding.py still fails on main for the other tools it lists, but gbuffer_census and navmesh_tile_obj drop out of the list with this PR (2 mentions on main, 0 here). The two guards are identical to the pattern the other tools use.
  • #7816, #7650 and #7174 cover other entries of the same test; none touches these two files.

AI-assisted (Claude Code).

@ps1ke

ps1ke commented Nov 23, 2026

Copy link
Copy Markdown

Correction to my review above: I said none of #7816, #7650 and #7174 touches these two files. That was wrong. #7816 ("guard stdout in the 11 tools test_tool_stdout_encoding lists") already changes both tools/gbuffer_census.py and tools/navmesh_tile_obj.py, so this PR overlaps it and whichever lands second will conflict or become a no-op. The test results I reported for f41d42611 stand; the overlap is a reason to check with #7816's author or the coordinator before merging both.

AI-assisted (Claude Code).

@Friendships6666

Copy link
Copy Markdown
Contributor Author

Thanks for testing this on Windows and Linux, and thanks, ps1ke, for the follow-up about the overlap. I confirmed that #7176 already includes both stdout guards, so there’s no need to review or merge them twice. I’m closing this PR in favor of #7176.

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.

3 participants