Skip to content

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

Closed
Andretuta wants to merge 1 commit into
mainfrom
old-pr/9861
Closed

Andretuta wants to merge 1 commit into
mainfrom
old-pr/9861

Conversation

@Andretuta

Copy link
Copy Markdown
Collaborator

Carried over from old PR 9861 by milas6669 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9861, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
milas6669: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Resubmission of #5760 (closed during repo transfer/purge at 22:47 UTC). Mergeable with current main with zero conflicts.

Claim: https://github.com/ItsNotRexed/Leonida/issues/5581#issuecomment-7100263084

What and why

Tests failed on Windows 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 POSIX there is nothing to escape, which is why the tests were green where they were written.

The messages now follow the idiom other tools use ({e.filename or <fallback>}: {e.strerror or e}), printing the path as written.

Tests run

python -I tests/test_bink_names.py     -> OK
python -I tests/test_opus_tags.py      -> OK
python -I tests/test_world_names.py    -> OK

Independently tested and verified on #5760 by @Atomic258, @YordiLorenzo, @LuanBogoqb, @cipher-droid.

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

@wavehs

wavehs commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Checked this branch: tests/test_bink_names.py, tests/test_opus_tags.py and tests/test_world_names.py all OK here. On the Windows runner the same three fail because OSError.__str__ prints the filename with %r and doubles every backslash; printing the plain path fixes the assertions as they stand, which is the better side to fix than the tests (I withdrew the test-side version, #69, in favour of this). Mergeable against current main.

@quartz-heron-58

Copy link
Copy Markdown
Contributor

Tested 82bdc54 (cherry-picked onto main 1c93c86) on native Windows 11 Home (build 26300), Python 3.12.10: pass.

On main 1c93c86, python -I tests/test_bink_names.py, tests/test_opus_tags.py and tests/test_world_names.py each fail one test here, with the doubled backslashes of the repr'd path in the message. With this commit all three files end in OK. python -m compileall -q make_game.py tools tests: exit 0. No game files.

Not checked: which of the two approaches discussed on #69 the project prefers; this only confirms that this one clears the three Windows failures.

AI-assisted (Claude Code ran the tests and wrote this comment).

@Mby159

Mby159 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Verified on native Windows, because the effect of this change is Windows-only and the Linux leg of CI cannot see it.

What I ran (Windows 11 x64 10.0.29712, Python 3.13, standard library only, no game files, no GPU):

python -I tests/test_bink_names.py
python -I tests/test_opus_tags.py
python -I tests/test_world_names.py

on this pull request's head 82bdc54ffea152d60f3290ba6a3119bd54661ec2, and on current main d7576d56ae2c77564c84ffae724ffe9bdd2e6701.

On this head: 36, 25 and 31 tests - all OK.

On main: each of the three fails with one failure, for the reason @Len1k described in #14 (comment):

AssertionError: 'C:\Users\...\mount\blocked' not found in "bink_names: error: [Errno 13] permission denied: 'C:\\Users\\...\\mount\\blocked'\n"

OSError.__str__ renders the filename with repr(), so on Windows every backslash in the message is doubled and the raw path is no longer in the text. Printing error.filename and error.strerror puts the plain path back, and the three tests pass unchanged.

Two notes for whoever merges this:

  • This is the tool-side fix, so the three tests keep their original meaning ("the report names the blocked path"). tests: match the path as the error message prints it on Windows #69 took the other side of it - changing the tests to expect the repr'd path - and was closed; the two cannot both land, because one asserts the doubled path and the other prints the plain one.
  • The Windows check job collects every failing file and then fails, so on main these three sit in front of everything after them in the standard-library loop.

Separately, tests/test_tool_stdout_encoding.py is red on current main for an unrelated reason: tools/exe_sha.py and tools/pr_conflict_label.py have no sys.stdout.reconfigure(errors="replace") in their __main__ block. This branch predates both tools, so that file is green here. I filed that separately as #605, so the Windows job has four red files on main, not three.

AI-assisted.

@nilparra-dev

Copy link
Copy Markdown

Independent check on native Windows 11, Python 3.13, stdlib only, from clean worktrees (no game files, no GPU):

One merge hazard: #763 (and its earlier draft #312) changes the same assertions to expect repr(blocked). Each side passes alone, but your tools plus #763's tests in one tree give 13 failures on Windows (1 + 11 + 1), while Linux CI stays green either way. Details are in the finding I posted on #14.

This is the side I would keep — printing a readable path is better than pinning doubled backslashes into the tests. If you want, I can take over the rebase and the close-out of #763/#312; I am not opening a competing PR.

AI-assisted.

@veqzo

veqzo commented Nov 24, 2026

Copy link
Copy Markdown

world_names.py can lose the requested output path when os.replace(tmp, path) fails. An OSError from a two-path operation can carry the destination in filename2, but the new handler prints only filename and strerror. The message then identifies the temporary file without identifying the output the user requested.

Could the handler print both paths when filename2 is present, with a synthetic failed-replace test?

AI-assisted review. I inspected the code; I did not run the project tests.

@abnalstlll-byte abnalstlll-byte 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.

Clean-Room Audit — PR #128 (bink_names, opus_tags, world_names OSError formatting)

Clean tool-side fix that formats {error.filename}: {error.strerror} instead of {error}, eliminating repr() path escaping differences between Windows and POSIX while keeping existing test assertions clean.

Verified clean diff and clean-room boundaries (0 game data); closed duplicate #763 in favor of this approach.

Verdict: APPROVED

@Anonymous78e

Copy link
Copy Markdown
Contributor

Independent Windows check of this PR, merged onto current main (507029d, merges cleanly; the merge touches only tools/bink_names.py, tools/opus_tags.py, tools/world_names.py).

Windows 11 Pro 26H2 (26300.9457), CPython 3.13.15, no game files:

test file main 507029d main + #128
python -I tests/test_world_names.py 31 run, 1 failure (test_an_unreadable_subtree_does_not_replace_the_dictionary) 31 run, OK
python -I tests/test_bink_names.py 36 run, 1 failure (test_unreadable_mount_directory_preserves_the_report) 36 run, OK
python -I tests/test_opus_tags.py 28 run, 1 failure (test_cli_reports_incomplete_directory_discovery) 28 run, OK

These are the three Windows-only failures reported today in the coordination issue (#14, the PermissionError repr finding): the tools print str(exc), whose quoted filename doubles the backslashes on Windows, so the assertion on the plain path fails. With this PR's plain-path message all three pass and nothing else in those files changes result.

AI-assisted: yes (Claude Code).

@OguzSoykan

Copy link
Copy Markdown

Verified on native Windows at head 82bdc54ff: test_bink_names.py, test_opus_tags.py and test_world_names.py fail on main and pass here. The test-side alternative #1425 also passes; only one direction should land. #1792 touches the same three tools.

Native Windows 10 Pro 19045, CPython 3.12, py -3.12 -I, checkout under a non-ASCII profile path (C:\Users\Oğuz\..., TEMP is the 8.3 alias C:\Users\OUZ~1\...). No game files.

AI-assisted (Claude Code).

@wavehs

wavehs commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Verified on main bd6ba97ab (macOS 27.2.1 arm64, Python 3.15.2). The diff applies cleanly and the three test files pass: test_bink_names, test_opus_tags, test_world_names all OK.

The Windows spelling does not occur naturally on macOS, so I drove each tool's OSError path with a synthetic backslash filename (OSError(2, "No such file or directory", r"C:\Users\runneradmin\AppData\Local\Temp\x.txt")) and captured stderr.

Before (unmodified main):

bink_names:  error: [Errno 2] No such file or directory: 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\x.txt'
opus_tags:   error: [Errno 2] No such file or directory: 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\x.txt'
world_names: ERROR: [Errno 2] No such file or directory: 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\x.txt'

(quoted path, every separator doubled — exactly what a Windows test cannot match against the plain str(path).)

After:

bink_names:  error: C:\Users\runneradmin\AppData\Local\Temp\x.txt: No such file or directory
opus_tags:   error: C:\Users\runneradmin\AppData\Local\Temp\x.txt: No such file or directory
world_names: ERROR: C:\Users\runneradmin\AppData\Local\Temp\x.txt: No such file or directory

error.filename or <the argument> also keeps a message when the exception carries no filename, and error.strerror or error still shows something for an OSError built without one. Looks right; this is the product-side fix, which is the one to take.

AI-assisted (verification only).

@wavehs

wavehs commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

A stronger reproduction, on macOS, of the exact Windows failure: point TMPDIR at a folder whose name contains a backslash and run the three files on unmodified main. The tools print the PermissionError filename through {e} (repr'd, every separator doubled), and the test's assertIn(str(path), stderr) sees the plain spelling:

test_bink_names.py  FAIL test_unreadable_mount_directory_preserves_the_report
  .../back\slash-tmp/.../mount/blocked not found in
  "bink_names: error: [Errno 13] permission denied: '...back\\\\slash-tmp...'"
test_opus_tags.py   FAIL test_cli_reports_incomplete_directory_discovery
  .../back\slash-tmp/.../opus/blocked not found in
  "opus_tags: error: [Errno 13] Permission denied: '...back\\\\slash-tmp...'"
test_world_names.py FAIL test_an_unreadable_subtree_does_not_replace_the_dictionary
  .../back\slash-tmp/.../manifests/blocked not found in
  "ERROR: [Errno 13] Permission denied: '...back\\\\slash-tmp...'"

With this PR applied, the same three files under the same TMPDIR are OK (Ran 36, Ran 28, Ran 31 tests). That is the same assertion the Windows check job makes, so this is the Windows red reproduced independently of a Windows runner.

(For anyone reusing the trick: TMPDIR backslashes turn CMake-argument tests red too, because CMake unescapes \s; those are not Windows failures. The three files above fail for the repr reason, which is the one this PR fixes.)

AI-assisted (verification only).

@wavehs

wavehs commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

This draft has a live, rebased duplicate: #1792 (Ch1mpleo, claimed as OLD-9861) carries the same old-pr/9861 change onto current main, non-draft and with the three files' tests run. I applied both diffs to main f107ae044: they differ only in blob hashes and line offsets, and both fix the three backslash-TMPDIR failures identically.

Nothing wrong with this branch — it just no longer needs to be merged on its own. Close it once #1792 lands (or let #1792 close in its favour if this draft is preferred, though the takeover copy is the ready one).

AI-assisted (review only).

@Andretuta

Copy link
Copy Markdown
Collaborator Author

Closing carried-over draft: superseded by live rebased PR #1792 (OLD-9861).

@Andretuta Andretuta closed this Nov 27, 2026
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.

10 participants