Skip to content

world_interior_names: report invalid --names and unwritable --out as exit 2 - #4823

Open
DenRakEiw wants to merge 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:fix/world-interior-names-io-errors
Open

DenRakEiw wants to merge 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:fix/world-interior-names-io-errors

Conversation

@DenRakEiw

Copy link
Copy Markdown
Contributor

Reports invalid/unreadable --names inputs and unwritable --out paths in tools/world_interior_names.py as single-line stderr errors with exit code 2 instead of unhandled tracebacks.

Changes

  • load_names() validates that the parsed JSON root and InteriorNames section are JSON objects (ValueError otherwise instead of AttributeError).
  • main() checks os.path.isdir(a.names) and loads a.names inside try ... except (OSError, ValueError) before scanning, exiting 2 with ERROR: cannot read ... on a directory, unreadable file, invalid UTF-8, malformed JSON, or non-object JSON.
  • main() checks os.path.isdir(a.out) before scanning and wraps os.makedirs + open(a.out, "w", encoding="utf-8", newline="\n") + json.dump in try ... except OSError, exiting 2 with ERROR: cannot write ... instead of a traceback.
  • Added synthetic unit tests in tests/test_world_interior_names.py (test_bad_names_file_is_one_error_line_before_scanning, test_unwritable_out_is_one_error_line).
  • Distinct from world_interior_names: preserve archive and names inputs when writing reports #4748 (which guards against --out overwriting input files) and world_interior_names: reject the arguments the run cannot honour #4690 (which validates --jobs and window arguments).

Claim

Claimed in #4683: #4683 (comment)

Testing

  • Environment: Windows 11, Python 3.12.10, CPU only (no GPU exercised, synthetic fixtures only, no game files).
  • python -I tests/test_world_interior_names.py -v: 12/12 OK.
  • python -I tests/test_text_write_line_endings.py: 3/3 OK.
  • python -m compileall -q tools/world_interior_names.py tests/test_world_interior_names.py & git diff --check: clean.

AI-assisted (Gemini 4 Neon).

@Atomic258

Atomic258 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested e10f890544916d1a6926e2aedb88e77a4a189e47 o
Wi
dows 11, Pytho
3.15.2 (CPU o
ly). pytho -I tests/test_world_i terior_ ames.py passed 12 tests; pytho -I tests/test_text_write_li e_e di gs.py passed 3. pytho -m compileall -q tools/world_i terior_ ames.py tests/test_world_i terior_ ames.py a
d git diff --check passed. Red co
trol: restored o
ly the tool from the pare
t, kept the PR tests, a
d rera
the world-i
terior suite; it failed with seve
u
caught exceptio
subtest errors. Restored PR versio
; worktree clea
.

AI-assisted (Devi
);
o game files.

@kapitche

Copy link
Copy Markdown
Contributor

Tested e10f890 merged with main 3faac55 on Linux (WSL2) Python 3.12.16 (-I): pass

tests/test_world_interior_names.py: 12 run / 12 passed / 0 failed. By hand on the CLI (empty folder as the scan path): --names as a JSON array, a malformed file, a non-UTF-8 file and {"InteriorNames": 5} each print ERROR: cannot read ... and exit 2; --names or --out pointing at a folder, and --out under a regular file, print ERROR: cannot ... and exit 2; {} and a section with odd items still exit 0 and write the summary.

Negative control: with tools/world_interior_names.py from main the test file gives 7 errors of 12; with the PR file all pass.

Not run natively on Windows (Linux only here); the PR already has a Windows check on this head.

@memorypressure

Copy link
Copy Markdown

Verified on Linux: merges cleanly with current main 3faac55, and tests/test_world_interior_names.py passes 12 tests under python -I (re-run), including the new exit-2 checks for unreadable --names (directory, bad UTF-8, malformed/non-object JSON) and unwritable --out, each asserting a single ERROR line and no traceback. UnicodeDecodeError being a ValueError subclass means the except clause genuinely covers the bad-UTF-8 case, the output write still pins newline with utf-8, and the mocked-scan test proves validation runs before scanning. Nothing on main touched these files since your base. This branch gets no CI runs, so treat this as the CI evidence. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@Atomic258

Copy link
Copy Markdown
Contributor

Tested e10f890 on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_world_interior_names.py -> OK

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

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 4a6c6575 merged onto main 561b65a8 on Windows 11, CPython 3.14.3, CPU only: pass.

  • python -I tests/test_world_interior_names.py: 29 tests OK.
  • Negative control (tools/world_interior_names.py from main, the PR's tests kept): tests/test_world_interior_names.py 29 tests FAILED (errors=1).
  • py_compile on the 2 changed Python files: OK; git diff --check: clean.

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

@kapitche

Copy link
Copy Markdown
Contributor

Tested 4a6c657 merged with main 8575d36 on Linux (WSL2) Python 3.12.16 (-I): pass
Clean merge. tests/test_world_interior_names.py: 29 tests OK.
Negative control: tools/world_interior_names.py reverted to main makes test_unwritable_out_is_one_error_line (file parent) error, so that case discriminates.
No other open PR found that does the same (#5274 is a different change to the same tool).

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.

5 participants