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

Closed
opened 2026-11-26 20:19:37 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/920
Author: @TuroYT
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @QemmHD

Base: main ← Head: fix/batch-glb-usage-exit


📝 Commits (2)

  • 540e522 batch_glb: exit 2 for a bad input or output folder (BATCH-GLB-USAGE-EXIT-STATUS)
  • dda55b6 batch_glb: wrap the exit status sentence in the module docstring

📊 Changes

2 files changed (+27 additions, -3 deletions)

View changed files

📝 tests/test_batch_glb.py (+24 -1)
📝 tools/batch_glb.py (+3 -2)

📄 Description

Claimed in the coordination issue as: BATCH-GLB-USAGE-EXIT-STATUS (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135524946)

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).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/920 **Author:** [@TuroYT](https://github.com/TuroYT) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@QemmHD](https://github.com/QemmHD) **Base:** `main` ← **Head:** `fix/batch-glb-usage-exit` --- ### 📝 Commits (2) - [`540e522`](https://github.com/ubiquitarianism/leonida/commit/540e522b364b884abc19d7d13ee4e687307de02f) batch_glb: exit 2 for a bad input or output folder (BATCH-GLB-USAGE-EXIT-STATUS) - [`dda55b6`](https://github.com/ubiquitarianism/leonida/commit/dda55b6f6c233f672d8d9445264c90b72cdefd2b) batch_glb: wrap the exit status sentence in the module docstring ### 📊 Changes **2 files changed** (+27 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_batch_glb.py` (+24 -1) 📝 `tools/batch_glb.py` (+3 -2) </details> ### 📄 Description Claimed in the coordination issue as: BATCH-GLB-USAGE-EXIT-STATUS (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135524946) ## 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). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:19:37 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#958
No description provided.