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

Manually merged
github merged 1 commit from gh-pr/1531/head into gh-pr/1531/base 2026-11-26 23:14:38 +00:00
Owner

@⁠RenzoWit35 on GitHub · 2026-11-24 13:43 UTC · original
RenzoWit35:tooling/ttpf-export-indices-errors → main · +38 −3 · 2 files · 1 commits · merged 2026-11-24 14:14 UTC

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.

**@⁠RenzoWit35** on GitHub · 2026-11-24 13:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1531) `RenzoWit35:tooling/ttpf-export-indices-errors` → `main` · +38 −3 · 2 files · 1 commits · merged 2026-11-24 14:14 UTC ## 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.
main() called parse_indices() outside the try block that turns other failures into parser.error(), so values such as 5-3, 1-, abc or -2 ended in a Python traceback with exit code 1. Route the ValueError through parser.error() (exit code 2) and replace the leaked int() message with one that names the bad token. Add a subprocess regression test for the four inputs plus a valid-value control.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:14:36 +00:00
github manually merged commit 3ff5655343 into gh-pr/1531/base 2026-11-26 23:14:38 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.