Skip to content

tools: print the plain path, not a repr'd one, in OSError messages - #5760

Open
milas6669 wants to merge 1 commit into
ItsNotRexed:mainfrom
milas6669:tools/plain-paths-in-error-messages
Open

milas6669 wants to merge 1 commit into
ItsNotRexed:mainfrom
milas6669:tools/plain-paths-in-error-messages

Conversation

@milas6669

@milas6669 milas6669 commented Nov 23, 2026 •

Copy link
Copy Markdown

Update (rebased onto origin/main 867d922f0): main's tools/bcpack_tool.py changed its same-input guard in the meantime (it now quotes the paths with '...', not !r), so this PR no longer touches it: three files, +12/-3. test_bcpack_tool.py passes on main's version. The other three tests still fail on main and pass here: test_bink_names (1 failure on main, OK 33 here), test_opus_tags (1 failure, OK 24), test_world_names (1 failure, OK 30). git diff --check clean. Overlap: #6049 and #5927 change the same three tools; this PR is the oldest of the three (12:01 UTC) and is mergeable again, so the maintainer can keep any one of them.

Claim: #5581 (comment)

What and why

Before the rebase, five tests failed on Windows at 561b65a8 because the tools put a repr'd path in their error text. str(OSError) reprs the filename it carries, so every separator doubles on Windows (C:\\Users\\...); on a POSIX path there is nothing to escape, which is why the tests were green where they were written. tools/bcpack_tool.py had the same bug written directly, with !r on both paths.

Failing before this change, passing after:

  • tests/test_bink_names.py::test_unreadable_mount_directory_preserves_the_report
  • tests/test_opus_tags.py::test_cli_reports_incomplete_directory_discovery
  • tests/test_world_names.py::test_an_unreadable_subtree_does_not_replace_the_dictionary
  • tests/test_bcpack_tool.py::test_decode_refuses_same_input_output_path
  • tests/test_bcpack_tool.py::test_decode_refuses_hardlink_output

The four messages now follow the idiom the other tools already use ({e.filename or <fallback>}: {e.strerror or e}, as in tools/anim_clips.py and tools/analyze_4240_full.py), so the user sees the path as written. bink_names and world_names keep their ValueError handling on a separate except clause, because those carry no filename and their messages are already plain.

This is the same rule #1692/#1848 settled for world_names' --out diagnostic ("print paths as written, so Windows paths match"); these four sites were missed.

Tests run

python -I tests/test_bink_names.py     -> OK   (was 1 failure)
python -I tests/test_opus_tags.py      -> OK   (was 1 failure)
python -I tests/test_world_names.py    -> OK   (was 1 failure)
python -I tests/test_bcpack_tool.py    -> OK   (was 2 failures)
python -I <the 342-file stdlib sweep>  -> 397 pass, 3 fail (was 393 pass, 7 fail)

The three that still fail are not this change: test_joaat_agreement.py (four open PRs already fix it), test_missing_input_exit_codes.py (numpy is not installed here) and test_first_look_rebuild.py (it tries to rebuild runtime/build/gta6rt.exe, so it needs a configured build).

python -m compileall -q on the four files: clean. git diff --check: clean.

Complements the open #4277, #4404 and #4728: those add the unlistable-folder handling around these messages, and their new tests will hit the same escaping on Windows without this.

No GPU used, no game data. AI-assisted.

Depends on: none.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 06d9cd06 on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_world_names.py -> OK - plain-path error message change keeps suite green

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@memorypressure

Copy link
Copy Markdown

Verified on your head at main 561b65a: compileall clean; test_bcpack_tool 18/18 (re-run), test_bink_names 33, test_opus_tags 20 and test_world_names 29 all pass with the new message format, and grep confirms no existing test asserts the old repr'd form. One nit: the bcpack_tool.py hunk rewords a ValueError, not an OSError, so the title slightly overreaches — harmless. The branch reports no CI checks — worth a push. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@kapitche

kapitche commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested 06d9cd0 merged with main 561b65a on Ubuntu (WSL2) / Python 3.12.16: pass

tests/test_bcpack_tool.py 18/18, test_bink_names.py 33/33, test_opus_tags.py 20/20, test_world_names.py 29/29, 0 failures. The PR adds no tests; I grepped those four test files and found none asserting the old "[Errno" / repr form. Behaviour check on an unhandled OSError (unreadable mount file, bink_names): main prints [Errno 13] Permission denied: '<path>', this head prints <path>: Permission denied. Missing-path cases already had their own messages and are identical on main and the PR. Negative control: none possible since there is no test; the before/after output is the evidence. Note the bcpack_tool.py hunk rewords a ValueError (drops the !r), not an OSError.

@0klavair

Copy link
Copy Markdown
Contributor

One more reason to land this soon: it also fixes a test that is red on main under Windows. tests/test_bink_names.py::TestCli::test_unreadable_mount_directory_preserves_the_report (added by bf8c548 today) fails on main because bink_names prints str(PermissionError), which doubles the backslashes ('C:\\Users\\...'). The test looks for the plain path. On Linux there's no backslash, so it passes there. With this PR (06d9cd06, merged onto current main): test_bink_names.py 33 passed, and bcpack_tool/opus_tags/world_names tests 66 passed, 1 skipped. Windows 11 / Python 3.12. AI-assisted.

@HQasper

HQasper commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Duplicate check with #5927, measured on this machine (Windows 11 build 26300, Python 3.13, both heads against
main 561b65a8):

python -I tests/... main 561b65a8 #5760 06d9cd06 #5927 ea61a859
test_bink_names.py 1 failure / 33 OK 33 OK 33
test_opus_tags.py 1 failure / 20 OK 20 OK 20
test_world_names.py 1 failure / 29 OK 29 OK 29
test_bcpack_tool.py 3 failures / 18 OK 18 OK 18

That is six red tests on this machine, not five: test_bcpack_tool fails on the hardlink, symlink and same-path
cases because {out_path!r} doubles every backslash - the same cause as the other three files. Both heads turn all
six green, and neither breaks a neighbour test (test_bcpack_tool passes at both heads).

The two patches are the same change in the same four files. The only difference is the case where
OSError.filename is None: #5760 falls back to the tool's input path (a.mount, a.opus), while #5927 prints
no path prefix and says why in a comment. On every path the tests exercise the output is identical, so this does
not separate them.

Keep #5760 and close #5927. #5760 came first (12:01 vs 12:35) and has three independent confirmations on its
thread - Windows Server 2022, WSL2/Ubuntu, and the red-on-main note - against one on #5927; both land the same six
greens. If the no-filename handling in #5927 is preferred, it is a three-line delta on top of #5760, not a reason
to land a second patch.

One caveat for whoever lands either: both heads leave tools/opus_tags.py:232 (cannot read a CSV: {e}) and
tools/bcpack_tool.py:224 (ERROR: {src}: {e}) unchanged - same pattern, no test covers them. The wider scan of
tools/ is a finding in the coordination issue.

AI-assisted.

@larpinguser larpinguser left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

Fixes repr'd paths in OSError messages across four tools: tools/bcpack_tool.py decode_file drops !r on the same-input guard; bink_names.py, opus_tags.py and world_names.py split OSError from ValueError and print error.filename/error.strerror so Windows separators are not doubled. Tests in the four corresponding test files were failing before this change and pass after.

Why merge

Makes five Windows test cases pass and shows paths as written rather than C:\\... reprs, following the idiom already used in anim_clips.py and analyze_4240_full.py.

Verdict: Approve

@larpinguser

Copy link
Copy Markdown

Summary

Fixes repr'd paths in OSError messages across four tools: tools/bcpack_tool.py decode_file drops !r on the same-input guard; bink_names.py, opus_tags.py and world_names.py split OSError from ValueError and print error.filename/error.strerror so Windows separators are not doubled. Tests in the four corresponding test files were failing before this change and pass after.

Why merge

Makes five Windows test cases pass and shows paths as written rather than C:\\... reprs, following the idiom already used in anim_clips.py and analyze_4240_full.py.

Verdict: Approve

@myokex

myokex commented Nov 23, 2026

Copy link
Copy Markdown

Tested 06d9cd066 merged onto main 8575d36ed on Windows 11, Python 3.12.10 (CPU only, no game files): pass. test_bcpack_tool (main: failures=2), test_bink_names, test_opus_tags and test_world_names (main: failures=1 each) are all OK with this PR.

Notes for picking between the overlapping PRs (#6049, #5927): tools/opus_tags.py:241 (cannot read a CSV: {e}) is not changed, so a CSV path still prints with doubled backslashes; and when an OSError has no filename, this prints a.mount / a.opus as the path, which may not be the file that failed. AI-assisted (Claude Code).

bink_names, opus_tags and world_names split OSError from ValueError and print the error's filename and strerror, so Windows path separators are no longer doubled by repr(). bcpack_tool's same-input guard was changed on main meanwhile, so this branch no longer touches it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@milas6669
milas6669 force-pushed the tools/plain-paths-in-error-messages branch from 06d9cd0 to 46fbe6e Compare November 23, 2026 19:29
@milas6669

Copy link
Copy Markdown
Author

Rebased onto origin/main 867d922f0 (head 46fbe6e19), mergeable again. The conflict was only in tools/bcpack_tool.py: main already changed that guard, so I took main's side and this PR is now bink_names, opus_tags and world_names (+12/-3). On this head, Windows 11, Python 3.14: test_bcpack_tool OK (18, 1 skipped), test_bink_names OK (33), test_opus_tags OK (24), test_world_names OK (30). With main's versions of those three tools the same three tests fail (1 failure each), so the change is still needed. Thanks @myokex for the Windows check; the opus_tags.py:241 CSV message you noticed is still not changed here, see #6049 for that one. AI-assisted (Claude Code).

@YordiLorenzo

Copy link
Copy Markdown

Tested 46fbe6e on Linux, Python 3.14.4: pass, one regression in the message

  • python -I tests/test_bink_names.py, test_opus_tags.py, test_world_names.py: OK
  • tools/world_names.py:674: _write_json ends in os.replace(tmp, path), whose OSError carries the temp file as filename and the --out path as filename2. With --out naming a non-empty folder, main prints "ERROR: [Errno 21] Is a directory: '.../report.json' -> '.../report_out'", this head prints "ERROR: .../.world-names-xxxx/report.json: Is a directory", a temp path that is already gone, and the --out path is lost. Fix: print exc.filename2 when it is set, for example "{exc.filename} -> {exc.filename2}".

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.

9 participants