textures: report malformed --indices as a usage error in the batch exporter #1524

Merged
RenzoWit35 merged 1 commit from upstream-pr/1531 into main 2026-11-24 14:14:37 +00:00
RenzoWit35 commented 2026-11-24 13:43:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-24T13:43:29Z.


Change

tools/ttpf_batch_export.py called parse_indices(args.indices) in main() outside the try block that turns other failures into parser.error(...). A malformed --indices value therefore ended in a raw Python traceback with exit code 1 instead of the tool's usage error (exit code 2).

  • main() now catches the ValueError from parse_indices and calls parser.error(f"--indices: {exc}"), matching the neighbouring failure handling.
  • A small _index_int helper replaces the bare int() calls so a non-integer token gives Invalid index 'abc' in 'abc': expected an integer instead of the Python-internal invalid literal for int() with base 10: ''.
  • Valid input and the existing Invalid range '5-3': start (5) > end (3) text are unchanged.

Verification

Windows 11, Python 3.14.5, base origin/main 1ca0dec1.

Before (unmodified origin/main, empty file as pool, python -B tools/ttpf_batch_export.py empty.ttpf -o <dir> --indices "<v>"), all four exit 1 with a full traceback:

  • 5-3: ValueError: Invalid range '5-3': start (5) > end (3)
  • 1-: ValueError: invalid literal for int() with base 10: ''
  • abc: ValueError: invalid literal for int() with base 10: 'abc'
  • -2: argparse accepts it as the option value (it looks like a negative number), then parse_indices splits it on - and fails with invalid literal for int() with base 10: ''. argparse behaviour is not changed.

After (same commands), each exits 2 with a one-line message and no traceback:

  • ttpf_batch_export.py: error: --indices: Invalid range '5-3': start (5) > end (3)
  • ttpf_batch_export.py: error: --indices: Invalid index '' in '1-': expected an integer
  • ttpf_batch_export.py: error: --indices: Invalid index 'abc' in 'abc': expected an integer
  • ttpf_batch_export.py: error: --indices: Invalid index '' in '-2': expected an integer

New test test_malformed_indices_are_usage_errors in tests/ttpf_batch_export_check.py runs the tool in a subprocess for the four values and asserts exit code 2, the --indices: message naming the bad token, no Traceback, and that no output directory is created. It also checks parse_indices("0-1,3") == [0, 1, 3] as a control.

  • out/pe-env/Scripts/python.exe -B tests/ttpf_batch_export_check.py: Ran 12 tests ... OK (skipped=1) (the skip was already present).
  • Negative control: with tools/ttpf_batch_export.py restored to origin/main, the same command gives FAILED (failures=4, skipped=1), each 1 != 2 with a traceback in stderr.

Not run: other test files. The test is already listed in AGENTS.md and the CI Python job, so no registration change was needed.

Evidence and follow-up

Draft PR #836 (Rust batch exporter) also modifies tools/ttpf_batch_export.py; the hunks here are small and in parse_indices and main(), so a textual conflict is possible but should be easy to resolve. No issue is linked.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6583156506 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1531). Originally posted by [RenzoWit35](https://github.com/RenzoWit35) on 2026-11-24T13:43:29Z. --- ## Change `tools/ttpf_batch_export.py` called `parse_indices(args.indices)` in `main()` outside the `try` block that turns other failures into `parser.error(...)`. A malformed `--indices` value therefore ended in a raw Python traceback with exit code 1 instead of the tool's usage error (exit code 2). - `main()` now catches the `ValueError` from `parse_indices` and calls `parser.error(f"--indices: {exc}")`, matching the neighbouring failure handling. - A small `_index_int` helper replaces the bare `int()` calls so a non-integer token gives `Invalid index 'abc' in 'abc': expected an integer` instead of the Python-internal `invalid literal for int() with base 10: ''`. - Valid input and the existing `Invalid range '5-3': start (5) > end (3)` text are unchanged. ## Verification Windows 11, Python 3.14.5, base `origin/main` 1ca0dec1. Before (unmodified `origin/main`, empty file as pool, `python -B tools/ttpf_batch_export.py empty.ttpf -o <dir> --indices "<v>"`), all four exit 1 with a full traceback: - `5-3`: `ValueError: Invalid range '5-3': start (5) > end (3)` - `1-`: `ValueError: invalid literal for int() with base 10: ''` - `abc`: `ValueError: invalid literal for int() with base 10: 'abc'` - `-2`: argparse accepts it as the option value (it looks like a negative number), then `parse_indices` splits it on `-` and fails with `invalid literal for int() with base 10: ''`. argparse behaviour is not changed. After (same commands), each exits 2 with a one-line message and no traceback: - `ttpf_batch_export.py: error: --indices: Invalid range '5-3': start (5) > end (3)` - `ttpf_batch_export.py: error: --indices: Invalid index '' in '1-': expected an integer` - `ttpf_batch_export.py: error: --indices: Invalid index 'abc' in 'abc': expected an integer` - `ttpf_batch_export.py: error: --indices: Invalid index '' in '-2': expected an integer` New test `test_malformed_indices_are_usage_errors` in `tests/ttpf_batch_export_check.py` runs the tool in a subprocess for the four values and asserts exit code 2, the `--indices:` message naming the bad token, no `Traceback`, and that no output directory is created. It also checks `parse_indices("0-1,3") == [0, 1, 3]` as a control. - `out/pe-env/Scripts/python.exe -B tests/ttpf_batch_export_check.py`: `Ran 12 tests ... OK (skipped=1)` (the skip was already present). - Negative control: with `tools/ttpf_batch_export.py` restored to `origin/main`, the same command gives `FAILED (failures=4, skipped=1)`, each `1 != 2` with a traceback in stderr. Not run: other test files. The test is already listed in `AGENTS.md` and the CI Python job, so no registration change was needed. ## Evidence and follow-up Draft PR #836 (Rust batch exporter) also modifies `tools/ttpf_batch_export.py`; the hunks here are small and in `parse_indices` and `main()`, so a textual conflict is possible but should be easy to resolve. No issue is linked. AI-assisted.
upstream-sync closed this pull request 2026-11-24 15:01:53 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
R0Y00/Xbox2Windows!1524
No description provided.