Skip to content

tools: a path outside the console's code page no longer crashes a tool's output - #1428

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
Dom-in:tools-stdout-codepage
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
Dom-in:tools-stdout-codepage

Conversation

@Dom-in

@Dom-in Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #1380 (comment) (@abilliontokens's finding 7078242007)

What and why

On Windows a redirected stdout (tool.py > log.txt, or a pipe) is encoded with the console's ANSI code page, and python -I ignores PYTHONUTF8 and PYTHONIOENCODING. A caller path with a character outside that code page therefore ends the run with UnicodeEncodeError as soon as a tool prints it. That covers a Cyrillic, Greek or CJK user name, or a Polish one under a code page that lacks it. stderr already escapes (backslashreplace); stdout is strict. #1406 fixed make_game.py.

Every CLI tool in tools/ (all 84 with a __main__ block) now starts that block the same way #1406 does:

if __name__ == "__main__":
    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
    sys.exit(main())

It's four lines per tool and nothing else changes. Importing a tool as a module, as the tests do, isn't affected.

Tested

Windows 11 Pro 26300, Python 3.13. Each input sits under a folder named with a private-use character that no ANSI code page maps.

  • Measured on main: given a zeroed input there, analyze_4240_full.py and meshlet_page.py die with UnicodeEncodeError on every run. audio_wav.py, hashdict.py and shader_profile.py die the same way once their --out already exists.

  • New tests/test_tool_stdout_encoding.py:

    • a static check that every tool's __main__ block sets errors="replace";
    • a rerun of the two always-crashing cases with redirected stdout.

    It passes here; with main's tools/ it fails 4 ways (the static check plus the two crashes, one listing 84 tools).

  • All 152 stdlib-only test files under tests/ (CI's selection): OK. pytest tests/test_tex_export.py tests/test_tex_headers.py tests/test_vertex_types.py: 181 passed. compileall: OK.

Not touched: tools/navmesh_index.py's case-sensitive containment check, the second half of the finding, which belongs to @bobcatchris's BUILD-350.

AI-assisted (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)

🤖 Generated with Claude Code

…l's output

On Windows a redirected stdout uses the console's ANSI code page, and python -I ignores PYTHONUTF8 and
PYTHONIOENCODING, so a caller path with a character outside that code page ended a run with
UnicodeEncodeError as soon as a tool printed it. ItsNotRexed#1406 fixed make_game.py; every CLI tool in tools/ now starts
its __main__ block the same way (stdout errors="replace").

tests/test_tool_stdout_encoding.py checks every tool's __main__ block and reruns two measured crashes
(analyze_4240_full.py, meshlet_page.py) with a private-use-named input. Found by @abilliontokens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Dom-in
Dom-in force-pushed the tools-stdout-codepage branch from e07f046 to f698bf2 Compare November 22, 2026 11:27
@Rainmaker33

Copy link
Copy Markdown

Tested f698bf2 on Windows 11 Pro 26300 with system code page 1253 (Greek), Python 3.14.0: the fix works, but the PR's own test fails on one tool.

The PR's diff applied cleanly to main bb2e184.

  • Fails: tests/test_tool_stdout_encoding.py reports test_every_main_block_reconfigures_stdout: Lists differ: ['bink_names.py'] != [].
    • tools/bink_names.py (c9650fe, 11:03 UTC) is in this PR's head, but its __main__ block is still the plain sys.exit(main()), so it is the 85th tool and needs the same four lines.
  • The real case works. I used a folder named café, since é is not in cp1253, with stdout redirected to a file:
    • main: analyze_4240_full.py dies with UnicodeEncodeError: 'charmap' codec can't encode character '\xe9'.
    • This PR: exit 0, with the path printed as caf?.

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Linux (WSL2 Ubuntu), Python 3.12, CPU only: fails after merging current main. tests/test_tool_stdout_encoding.py flags tools/bink_names.py (added by #1403 since this branched) for missing the reconfigure(errors="replace") line. Adding it there should fix that. The PR covers 84 tools, including saves.py (same fix as #1438, and it conflicts with #1438 there). It merges cleanly with the other open tool PRs I tried. Spot-check: saves.py info under cp1252 stdout exits 0.

…after this branched)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@kapitche thanks, that's the static check doing its job: tools/bink_names.py arrived with #1403 after this branched. Rebased onto current main and guarded it (a9d8f29); tests/test_tool_stdout_encoding.py is OK again with every tool in main covered. AI-assisted (Claude Code).

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking CI issue remains at the current head: the regression test scans the merged tools tree, where tools/bink_names.py is present from #1403 but is not updated by this PR. The same missing reconfigure call is reproduced in the two review comments above. Please include that entrypoint so the new test passes against current main.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest commit adds the missing bink_names.py stdout guard, matching the reported regression-test failure. The concrete issue from my earlier review is resolved; the latest CI checks are still running.

ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
… unencodable stdout

- d3d12_compute_test and d3d12_draw_test (built when glslangValidator is found) had no add_test, which
  test_ctest_registration catches; registered like their neighbours (exit 77 is a skip).
- awc_names.py (#1421) and bink_names.py (#1403) are new tools without #1428's stdout errors='replace' guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@UlteriorMotive00

Copy link
Copy Markdown
Contributor

Tested a9d8f29 (0 behind main) on Windows 11 Home 10.0.26300, with ANSI code page 1252, the case this PR is for. Python 3.14.7, pytest 9.2.0.

run this PR main
pytest tests/test_tool_stdout_encoding.py (main's versions of the 85 changed tools restored for the main column) 2 passed, 2 subtests 3 failed, 1 passed
python -I tools/saves.py info "セーブ/slot.bin" > out.txt (synthetic 10-byte file) exit 0, ???/slot.bin: unknown (10 bytes) exit 2, ERROR: 'charmap' codec can't encode characters

Overlap: #1426 fixes the same saves.py crash with errors='backslashreplace', so it prints セーブ/slot.bin instead of ???. The two will conflict in tools/saves.py. Escaping keeps the path recoverable from the output, which may be the better choice for every tool here.

AI-assisted (Claude Code). No game files.

@ItsNotRexed
ItsNotRexed merged commit c58a348 into ItsNotRexed:main Nov 22, 2026
10 of 11 checks passed
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
…AT_SUPPORT check, four tools' stdout

- run_gpu_tests.py: #1541's wave64 pixel fixtures (runtime/test/shaders/w64_graphics.py FIXTURES, tiers A-C) are
  checked by that runner; run_gpu_tests picked up their .asm and failed 14 of them with "no checker defined".
  It now leaves w64_graphics.FIXTURES to that runner.
- d3d12_d24_support_test (#1493): expected DEPTH_STENCIL in FORMAT_SUPPORT for R24G8_TYPELESS. Measured here, the
  host D3D12 (RTX 4060 Ti and WARP) reports 0x001010b0 for R24G8_TYPELESS and 0x003110b0 (DEPTH_STENCIL) only for
  D24_UNORM_S8_UINT, which #1511's per-format rules follow; the check now expects the bit for the typed format only.
- fma_mix_probe, text_tables, wave64_halves, xdxr_bvh: new tools without #1428's stdout errors='replace' guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AlxcBTW added a commit to AlxcBTW/Leonida that referenced this pull request Nov 22, 2026
…ools (ItsNotRexed#1428)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
…d stdout

- #1617 and #1620 both handle the float MODE fields gfx1170+ can't set. #1620's runner returns the reason for
  that kernel and runs the rest; #1617's test still expected Unavailable for the whole run. The test now checks
  the per-kernel reason.
- fspx_unpack.py, user_sgpr_census.py, world_lights_paths.py: new tools without #1428's stdout errors='replace'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Dom-in
Dom-in deleted the tools-stdout-codepage branch November 22, 2026 14:23
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
…four tools follow the repo rules

- int_hw_probe: VOP3 clamp on the carry-out add/sub ops (#1831) and v_cvt_rpi/flr's exact floor(x+0.5) and NaN
  sign saturation (#1856) now translate as gfx1035 measured, so KNOWN_DIVERGENCES is empty. The known-divergence
  test reports a synthetic entry. shader_validation.md says so, and design.md loses the stale duplicate
  v_cvt_flr/rpi row a "both" merge left that still called them open.
- docs/README.md: one Other languages line (fr, pt-BR, zh-CN, pl-PL, tr, ru, ja); docs/i18n/README.md: one row
  each for pt-BR and zh-CN (the newer).
- anim_rigs, d16_format_probe, pe_shader_containers: text writes name newline="\n" (#1615);
  pe_shader_containers guards stdout (#1428).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

6 participants