batch_glb: exit 2 for a bad input or output folder, 1 only for a failed model (BATCH-GLB-USAGE-EXIT-STATUS) #920

Manually merged
github merged 2 commits from gh-pr/920/head into gh-pr/920/base 2026-11-26 09:28:18 +00:00
Owner

@⁠TuroYT on GitHub · 2026-11-24 15:11 UTC · original
TuroYT:fix/batch-glb-usage-exit → main · +27 −3 · 2 files · 2 commits · merged 2026-11-24 20:04 UTC

Claimed in the coordination issue as: BATCH-GLB-USAGE-EXIT-STATUS (#14)

What was wrong

tools/batch_glb.py documents "Exit status is 1 only when a model failed" (docstring, lines 8-9). But main() (line 265-267) catches (ValueError, OSError) from batch_convert and returns 1. Those errors are input and output setup errors, not failed models:

  • batch_convert raises ValueError for a missing input folder.
  • os.makedirs raises OSError when the output path is a file or cannot be created.

Reproduction on origin/main:

$ python3 -I -B tools/batch_glb.py /nonexistent_in_dir /nonexistent_out_dir
ERROR: Input directory does not exist: /nonexistent_in_dir
exit=1
$ python3 -I -B tools/batch_glb.py /usr/share/doc /etc/hostname
ERROR: [Errno 17] File exists: '/etc/hostname'
exit=1
$ python3 -I -B tools/batch_glb.py --bogus
... error: the following arguments are required: in_dir, out_dir
exit=2

The input check in batch_convert runs before os.makedirs, so the file-as-output case writes nothing.

Why one return is enough

Per-model errors never reach that except. convert_single catches every Exception and returns it as a failure, so a corrupt model or a bad texture is counted and returns 1 through the existing line return 0 if stats["failed"] == 0 else 1. I checked that no other ValueError or OSError can escape the try for a single model.

What changed

  • main(): the setup-error branch returns 2 instead of 1.
  • Docstring: one sentence saying a missing input folder or an output path that cannot be created exits 2.
  • tests/test_batch_glb.py: test_cli_reports_directory_setup_errors expected 1 for both cases; it now expects 2. New test_cli_exit_status_follows_the_docstring pins the other exit codes: an empty input folder returns 0, a folder with one corrupt model returns 1, and an argparse usage error returns 2.

No caller, script or doc in the repository depends on exit 1 for these errors (git grep batch_glb finds only the tool and its test).

Tested

$ python3 -I tests/test_batch_glb.py          (fixed code)
Ran 16 tests ... OK

$ python3 -I tests/test_batch_glb.py          (origin/main tools/batch_glb.py swapped in)
FAIL: test_cli_reports_directory_setup_errors ... AssertionError: 1 != 2   (2 subtests)
FAILED (failures=2)

The new exit-status test passes on both versions by design: it pins the cases that were already correct, so a fix that over-corrects would fail it.

Edge cases run by hand on the fixed code:

$ python3 -I -B tools/batch_glb.py /nonexistent_in_dir /tmp/.../out_x     -> exit 2
$ python3 -I -B tools/batch_glb.py /usr/share/doc /etc/hostname            -> exit 2
$ python3 -I -B tools/batch_glb.py <file>.obj <out>                         -> exit 2 (input is a file)
$ python3 -I -B tools/batch_glb.py <empty dir> /etc/hostname/sub            -> exit 2 (ERROR: [Errno 20] Not a directory)
$ python3 -I -B tools/batch_glb.py <empty dir> <out>                        -> 0 (converted 0/0 models, 0 failed)
$ python3 -I -B tools/batch_glb.py <dir with broken.obj> <out>              -> 1 (converted 0/1 models, 1 failed)

Other checks:

$ python3 -m compileall -q tools tests                    (no output, ok)
$ python3 -I tests/test_text_write_line_endings.py        Ran 3 tests ... OK
$ python3 -I scripts/check_no_game_data.py tools/batch_glb.py tests/test_batch_glb.py   exit 0
$ git diff --check                                        (no output)

Inputs are hand-made: a two-line OBJ and empty folders. No game files, no GPU.

Not tested

  • Windows (paths and os.makedirs errors differ there). Only Linux was run.
  • Unreadable input folder and unwritable output folder (permission errors). Only the missing-path and file-path cases were run.
  • The texture and DDS paths, which this change does not touch.

AI-assisted (Claude Code).

**@⁠TuroYT** on GitHub · 2026-11-24 15:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/920) `TuroYT:fix/batch-glb-usage-exit` → `main` · +27 −3 · 2 files · 2 commits · merged 2026-11-24 20:04 UTC Claimed in the coordination issue as: BATCH-GLB-USAGE-EXIT-STATUS (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ## What was wrong `tools/batch_glb.py` documents "Exit status is 1 only when a model failed" (docstring, lines 8-9). But `main()` (line 265-267) catches `(ValueError, OSError)` from `batch_convert` and returns 1. Those errors are input and output setup errors, not failed models: - `batch_convert` raises `ValueError` for a missing input folder. - `os.makedirs` raises `OSError` when the output path is a file or cannot be created. Reproduction on origin/main: ``` $ python3 -I -B tools/batch_glb.py /nonexistent_in_dir /nonexistent_out_dir ERROR: Input directory does not exist: /nonexistent_in_dir exit=1 $ python3 -I -B tools/batch_glb.py /usr/share/doc /etc/hostname ERROR: [Errno 17] File exists: '/etc/hostname' exit=1 $ python3 -I -B tools/batch_glb.py --bogus ... error: the following arguments are required: in_dir, out_dir exit=2 ``` The input check in `batch_convert` runs before `os.makedirs`, so the file-as-output case writes nothing. ## Why one `return` is enough Per-model errors never reach that `except`. `convert_single` catches every `Exception` and returns it as a failure, so a corrupt model or a bad texture is counted and returns 1 through the existing line `return 0 if stats["failed"] == 0 else 1`. I checked that no other `ValueError` or `OSError` can escape the `try` for a single model. ## What changed - `main()`: the setup-error branch returns 2 instead of 1. - Docstring: one sentence saying a missing input folder or an output path that cannot be created exits 2. - `tests/test_batch_glb.py`: `test_cli_reports_directory_setup_errors` expected 1 for both cases; it now expects 2. New `test_cli_exit_status_follows_the_docstring` pins the other exit codes: an empty input folder returns 0, a folder with one corrupt model returns 1, and an argparse usage error returns 2. No caller, script or doc in the repository depends on exit 1 for these errors (`git grep batch_glb` finds only the tool and its test). ## Tested ``` $ python3 -I tests/test_batch_glb.py (fixed code) Ran 16 tests ... OK $ python3 -I tests/test_batch_glb.py (origin/main tools/batch_glb.py swapped in) FAIL: test_cli_reports_directory_setup_errors ... AssertionError: 1 != 2 (2 subtests) FAILED (failures=2) ``` The new exit-status test passes on both versions by design: it pins the cases that were already correct, so a fix that over-corrects would fail it. Edge cases run by hand on the fixed code: ``` $ python3 -I -B tools/batch_glb.py /nonexistent_in_dir /tmp/.../out_x -> exit 2 $ python3 -I -B tools/batch_glb.py /usr/share/doc /etc/hostname -> exit 2 $ python3 -I -B tools/batch_glb.py <file>.obj <out> -> exit 2 (input is a file) $ python3 -I -B tools/batch_glb.py <empty dir> /etc/hostname/sub -> exit 2 (ERROR: [Errno 20] Not a directory) $ python3 -I -B tools/batch_glb.py <empty dir> <out> -> 0 (converted 0/0 models, 0 failed) $ python3 -I -B tools/batch_glb.py <dir with broken.obj> <out> -> 1 (converted 0/1 models, 1 failed) ``` Other checks: ``` $ python3 -m compileall -q tools tests (no output, ok) $ python3 -I tests/test_text_write_line_endings.py Ran 3 tests ... OK $ python3 -I scripts/check_no_game_data.py tools/batch_glb.py tests/test_batch_glb.py exit 0 $ git diff --check (no output) ``` Inputs are hand-made: a two-line OBJ and empty folders. No game files, no GPU. ## Not tested - Windows (paths and `os.makedirs` errors differ there). Only Linux was run. - Unreadable input folder and unwritable output folder (permission errors). Only the missing-path and file-path cases were run. - The texture and DDS paths, which this change does not touch. AI-assisted (Claude Code).
A missing input folder or an output path that cannot be created raised
ValueError/OSError in batch_convert and main returned 1, the code the
docstring reserves for a failed model. Those errors now return 2, like
argparse usage errors. Per-model errors are caught in convert_single and
still return 1.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:28:16 +00:00
github manually merged commit dda55b6f6c into gh-pr/920/base 2026-11-26 09:28:18 +00:00
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-24 16:14 UTC · original

Independent test of #920 (BATCH-GLB-USAGE-EXIT-STATUS)

Head tested: 540e522b36 (merge base a2892784). Environment: Windows 11, native Python 3.13.13, no GPU. This covers the Windows run that the PR lists as not tested.

Commands and results:

  • python -I -B tests/test_batch_glb.py: Ran 16 tests, OK.
  • Same test file with tools/batch_glb.py from the merge base: test_cli_reports_directory_setup_errors FAILS in both subtests (1 != 2). As the PR says, test_cli_exit_status_follows_the_docstring passes on both versions by design.
  • Manual runs with Windows paths (--jobs 1):
    • Missing input folder: ERROR: Input directory does not exist: ..., exit 2.
    • Output path is an existing file: ERROR: [WinError 183] ..., exit 2.
    • Input path is a file: exit 2.
  • git merge-tree --write-tree origin/main <head> (origin/main 0af7753c): clean.
  • python -I scripts/check_no_game_data.py on the changed files: exit 0. git diff --check: clean.

Findings:

  • tools/batch_glb.py:267: the change is a single return code, and the reasoning in the PR holds. Per-model errors are caught in convert_single and counted, so only setup errors reach this except. No other script or doc calls batch_glb.py.
  • Exit 2 is now shared by argparse usage errors and setup errors, which matches the other tools that use 2 for "bad input".
  • Pre-existing, out of scope: an input path that is a file reports Input directory does not exist, which is misleading. "is not a directory" would be clearer. Not blocking.
  • Nit: the new docstring sentence at tools/batch_glb.py:9 runs past the wrap width of the surrounding paragraph.

Verdict: looks good.

AI-assisted.

**@⁠kawaii-shakal** on GitHub · 2026-11-24 16:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/920#issuecomment-7137332965) Independent test of #920 (BATCH-GLB-USAGE-EXIT-STATUS) Head tested: 540e522b364b884abc19d7d13ee4e687307de02f (merge base a2892784). Environment: Windows 11, native Python 3.13.13, no GPU. This covers the Windows run that the PR lists as not tested. Commands and results: - `python -I -B tests/test_batch_glb.py`: Ran 16 tests, OK. - Same test file with `tools/batch_glb.py` from the merge base: `test_cli_reports_directory_setup_errors` FAILS in both subtests (`1 != 2`). As the PR says, `test_cli_exit_status_follows_the_docstring` passes on both versions by design. - Manual runs with Windows paths (`--jobs 1`): - Missing input folder: `ERROR: Input directory does not exist: ...`, exit 2. - Output path is an existing file: `ERROR: [WinError 183] ...`, exit 2. - Input path is a file: exit 2. - `git merge-tree --write-tree origin/main <head>` (origin/main 0af7753c): clean. - `python -I scripts/check_no_game_data.py` on the changed files: exit 0. `git diff --check`: clean. Findings: - tools/batch_glb.py:267: the change is a single return code, and the reasoning in the PR holds. Per-model errors are caught in `convert_single` and counted, so only setup errors reach this `except`. No other script or doc calls `batch_glb.py`. - Exit 2 is now shared by argparse usage errors and setup errors, which matches the other tools that use 2 for "bad input". - Pre-existing, out of scope: an input path that is a file reports `Input directory does not exist`, which is misleading. "is not a directory" would be clearer. Not blocking. - Nit: the new docstring sentence at tools/batch_glb.py:9 runs past the wrap width of the surrounding paragraph. Verdict: looks good. AI-assisted.
Author
Owner

@⁠TuroYT on GitHub · 2026-11-24 17:05 UTC · original

Thanks for the Windows run.

Pushed dda55b6f6: the docstring sentence at line 9 now wraps like the rest of the paragraph (comment change only; tests/test_batch_glb.py still passes, 16 tests).

Not changed: the "Input directory does not exist" message for an input path that is a file. It was already like that and is outside this claim; I will post it as a finding: in the coordination issue if nobody has.

**@⁠TuroYT** on GitHub · 2026-11-24 17:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/920#issuecomment-7138665184) Thanks for the Windows run. Pushed dda55b6f6: the docstring sentence at line 9 now wraps like the rest of the paragraph (comment change only; `tests/test_batch_glb.py` still passes, 16 tests). Not changed: the "Input directory does not exist" message for an input path that is a file. It was already like that and is outside this claim; I will post it as a `finding:` in the coordination issue if nobody has.
Author
Owner

@⁠MoonEyes on GitHub · 2026-11-24 17:39 UTC · original · approved these changes

LGTM. Measured on Windows 11, Python 3.14, against main cf4c00cba:

  • python -I tests/test_batch_glb.py: main Ran 15, OK; this PR and a local merge into main Ran 16, OK.
  • A missing input folder exits 1 on main and 2 here; an empty folder exits 0 on both.
  • Mutation: with main's tools/batch_glb.py, test_cli_reports_directory_setup_errors fails in both subtests. Note that test_cli_exit_status_follows_the_docstring also passes with main's tools/batch_glb.py, so it guards the 0/1/2 contract rather than this fix.

AI-assisted: yes (Claude Code ran the checks; I read them).

**@⁠MoonEyes** on GitHub · 2026-11-24 17:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/920#pullrequestreview-6044345743) · **approved these changes** LGTM. Measured on Windows 11, Python 3.14, against main cf4c00cba: - `python -I tests/test_batch_glb.py`: main `Ran 15, OK`; this PR and a local merge into main `Ran 16, OK`. - A missing input folder exits 1 on main and 2 here; an empty folder exits 0 on both. - Mutation: with main's `tools/batch_glb.py`, `test_cli_reports_directory_setup_errors` fails in both subtests. Note that `test_cli_exit_status_follows_the_docstring` also passes with main's `tools/batch_glb.py`, so it guards the 0/1/2 contract rather than this fix. AI-assisted: yes (Claude Code ran the checks; I read them).
Author
Owner

@⁠QemmHD on GitHub · 2026-11-24 20:04 UTC · original

Merging.

Why merged: BATCH-GLB-USAGE-EXIT-STATUS: batch_glb exits 2 for a bad input or output folder, and 1 only when a model actually failed, so callers can tell usage errors from conversion failures. kawaii-shakal tested 540e522b on Windows (the later push was comment-only), and MoonEyes approved after that push.

Why it's good: test_batch_glb: 16 passed.

Tested on Windows 11 / RTX 4070 SUPER: merged alone onto main 6293c1c4f. With it in, the repo-consistency set (cmake/translator-deps, shader_stage_resume, runtime_paths, docs, make_game, no-game-data, run_semantic_tests) gives 571 passed / 5 skipped / 0 failed, and check_no_game_data on the changed files is clean. Security read of the three-dot diff: no binaries, game data, downloads, network calls, new env vars or build/CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠QemmHD** on GitHub · 2026-11-24 20:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/920#issuecomment-7143009659) Merging. **Why merged:** BATCH-GLB-USAGE-EXIT-STATUS: batch_glb exits 2 for a bad input or output folder, and 1 only when a model actually failed, so callers can tell usage errors from conversion failures. kawaii-shakal tested 540e522b on Windows (the later push was comment-only), and MoonEyes approved after that push. **Why it's good:** test_batch_glb: 16 passed. Tested on Windows 11 / RTX 4070 SUPER: merged alone onto main 6293c1c4f. With it in, the repo-consistency set (cmake/translator-deps, shader_stage_resume, runtime_paths, docs, make_game, no-game-data, run_semantic_tests) gives 571 passed / 5 skipped / 0 failed, and check_no_game_data on the changed files is clean. Security read of the three-dot diff: no binaries, game data, downloads, network calls, new env vars or build/CI changes. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.