Skip to content

ped_assemble: an unwritable --json/--out path is one ERROR line and exit 2, not a traceback - #6004

Open
evilclanker9000 wants to merge 2 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/1-pedassemble-json-write
Open

evilclanker9000 wants to merge 2 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/1-pedassemble-json-write

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

What and why

tools/ped_assemble.py writes its --json report (and --out) with os.makedirs + open outside any handler, and main() caught only PedAssembleError. A report path it cannot write — a parent folder that is an existing file, for example — therefore ended in a FileExistsError traceback and exit 1 instead of the one-line error the other tools give.

main() now catches OSError together with PedAssembleError, so the CLI prints ERROR: <the OS message, which names the path> and exits 2.

Test

Hand-written OBJ triangle plus a regular file standing where the report folder would be:

python -I tests/test_ped_assemble_json_write.py

Before (git checkout -- tools/ped_assemble.py):

AssertionError: 1 != 2 : Traceback (most recent call last):
    os.makedirs(parent, exist_ok=True)
FAILED (failures=1)

After:

Ran 1 test in 0.163s

OK

Also python -m compileall -q tools/ped_assemble.py tests/test_ped_assemble_json_write.py passes.

GPU

None needed: the tool and the test are standard-library Python over a hand-written OBJ file.

Notes

  • The OS message already contains the full path, so I did not add a second line of my own; that matches what bcpack_history_calib.py does with its OSError handler.
  • --out gets the same treatment because it goes through the same open calls; the new test covers the --json path only.
  • Malformed JSON input is still a separate concern and untouched here.

EGEN-PEDASSEMBLE-JSON-WRITE

AI-assisted.

…a traceback

The report writer creates the parent folder and opens the file outside any handler, so a parent that is an existing file (or any other unwritable path) raised FileExistsError past main(), which caught only PedAssembleError. Catch OSError there like the other tools do, so the CLI exits 2 with the path in one ERROR line.
…not a traceback

A hand-written OBJ triangle plus a file standing where the report folder should be: without the fix main() exits 1 with FileExistsError in a traceback; with it the run prints ERROR: ... and exits 2.
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

At f898b44b, the new diagnostic works, but a failed report write still replaces an existing GLB. The tool can detect this particular error before it builds the mesh.

To reproduce in an empty scratch directory on Windows, set $tool to the absolute path of tools/ped_assemble.py and run:

$v = "v 0 0 0`nv 1 0 0`nv 0 1 0`nf 1 2 3`n"
Set-Content part.obj $v -NoNewline
py -3.14 -I $tool assemble part.obj -o out.glb
$before = (Get-FileHash out.glb).Hash
Set-Content part.obj ($v.Replace('v 1 0 0', 'v 7 0 0')) -NoNewline
Set-Content blocker 'x'
py -3.14 -I $tool assemble part.obj -o out.glb --json blocker/report.json
$LASTEXITCODE
(Get-FileHash out.glb).Hash -eq $before

The last two results are 2 and False. The report is absent. Expected for a report parent that is already a regular file: reject the path before writing the GLB and preserve the previous export. The merge base 561b65a8 also replaces the GLB. It exits 1 with a traceback.

All 15 tests across test_ped_assemble.py and test_ped_assemble_json_write.py pass on Windows 11, CPython 3.14.7. Open PR #5764 also changes the same exception handler and adds output path checks.

AI-assisted.

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested f898b44b on Linux, CPython 3.14, CPU only, synthetic inputs, merged onto main 867d922f: pass

  • python -I tests/test_ped_assemble_json_write.py: Ran 1 test, OK. With only the non-test files reverted to main: FAILED (failures=1), so the new tests exercise the change.
  • compileall and scripts/check_no_game_data.py on the changed files: clean.

For whoever merges: #5764 (which I verified earlier) rewrites the same except line to a superset (PedAssembleError, OSError, ValueError). The agent reports that with #5764 alone this PR's test already passes; I did not repeat that combination. If so, this PR is subsumed.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting.

@AsgerCode

Copy link
Copy Markdown

Tested f898b44 on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass

What I ran:

Each bad path through the CLI, on the merged tree, with a hand-written OBJ triangle:

Case Exit Last stderr line
-o parent is a file 2 ERROR: [WinError 183] Cannot create a file when that file already exists: ...
-o is a folder 2 ERROR: [WinError 5] Access is denied: ...
-o <tmp>/bad<n>.glb 2 ERROR: [WinError 123] The filename, directory name, or volume label syntax is incorrect: ...
-o read-only existing GLB 2 ERROR: [WinError 5] Access is denied: ... (see 1 below)
--json folder / read-only / r<1>.json 2 [Errno 13] Permission denied / [Errno 13] / [Errno 22] Invalid argument
cull-overlap -o and inspect-seams --json with a file as parent 2 [WinError 183] ...
input missing / locked with no sharing / 0-byte OBJ 2 [Errno 2] / [Errno 13] / No non-empty mesh parts to export

No traceback in any case.

Not blocking for this PR, but the one-line error now hides two problems:

  1. -o naming a read-only GLB leaves a read-only .glb-<random>.tmp beside it. glb_writer._write_bytes_atomic gives the staging file the destination's read-only mode (published_mode), os.replace then fails, and the os.remove in the cleanup fails too and is ignored. The merge base does the same (with a traceback), and so does main + ped_assemble: guard output paths and report I/O or JSON errors with exit 2 #5764. A fix belongs in glb_writer._write_bytes_atomic: clear the read-only bit before the cleanup remove. file_mode.discard_staged from open Tools: clean read-only staging temps after a failed report replace #4516 does this, but Tools: clean read-only staging temps after a failed report replace #4516 does not apply it to glb_writer.
  2. A path that names an input still exits 0 and overwrites data: -o part.obj replaces the OBJ with the GLB, --json part.obj replaces it with the report, and --json equal to -o replaces the GLB with the report. ped_assemble: guard output paths and report I/O or JSON errors with exit 2 #5764 refuses all three with exit 2 (would overwrite input, name the same file).

Overlap: #5764 changes the same except line to (PedAssembleError, OSError, ValueError), so git merge-tree shows a conflict in tools/ped_assemble.py. Because #5764 passes this PR's test and also adds the guards in 2, only one of the two needs to merge. This PR merges clean with #6431, #5824, #6037, #6119 and #6199.

AI-assisted (Claude Code).

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.

4 participants