fix(tools): handle git command failures gracefully #7456

Merged
Cankiee merged 3 commits from upstream-pr/7456 into main 2026-10-20 10:25:54 +00:00
Cankiee commented 2026-10-18 08:13:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Cankiee on 2026-10-18T08:13:15Z.


What

Improve error handling in tools/check_conventions.py when Git commands fail.

Previously, providing an invalid base or head revision caused an unhandled subprocess.CalledProcessError traceback.

This PR:

  • Handles Git command failures and displays a readable error message on stderr.
  • Exits with status code 2 instead of displaying a Python traceback.
  • Handles missing Git executables with a clear error message.
  • Adds two regression tests covering invalid base and head revisions.

Tested

Environment: Windows, Git Bash, Python 3.14.

  • python -m unittest discover -s tools -p "test_check_conventions_git.py" -v — passed (2 tests).
  • python -m py_compile tools/check_conventions.py — passed.
  • git diff --check — passed.
  • Manually verified invalid base revision handling — passed.
  • Repository conventions check — passed.

No PS5 hardware or GPU testing required for this Python tooling change.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file (not applicable)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (no third-party code added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes ChatGPT assisted with code implementation. Changes were tested locally.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4907506391 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7456). Originally posted by [Cankiee](https://github.com/Cankiee) on 2026-10-18T08:13:15Z. --- ### What Improve error handling in `tools/check_conventions.py` when Git commands fail. Previously, providing an invalid base or head revision caused an unhandled `subprocess.CalledProcessError` traceback. This PR: - Handles Git command failures and displays a readable error message on stderr. - Exits with status code 2 instead of displaying a Python traceback. - Handles missing Git executables with a clear error message. - Adds two regression tests covering invalid base and head revisions. ### Tested Environment: Windows, Git Bash, Python 3.14. - `python -m unittest discover -s tools -p "test_check_conventions_git.py" -v` — passed (2 tests). - `python -m py_compile tools/check_conventions.py` — passed. - `git diff --check` — passed. - Manually verified invalid base revision handling — passed. - Repository conventions check — passed. No PS5 hardware or GPU testing required for this Python tooling change. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [[technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md)](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [[technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt)](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file (not applicable) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (no third-party code added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes ChatGPT assisted with code implementation. Changes were tested locally.
Cankiee commented 2026-10-18 10:51:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Cankiee on 2026-10-18T10:51:33Z.


I manually reviewed the overlap warning regarding #6447.

Both PRs modify tools/check_conventions.py, but they address separate issues.

PR #6447 modifies the conventions checker's handling of Markdown fences and other checks, while this PR adds error handling for failed Git subprocess calls.

I also inspected the git() function in PR #6447 and confirmed that it retains the original implementation without CalledProcessError or FileNotFoundError handling.

Based on this comparison, I found no duplicate implementation of the functionality introduced by this PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6248954734 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7456#issuecomment-6248954734). Originally posted by [Cankiee](https://github.com/Cankiee) on 2026-10-18T10:51:33Z. --- I manually reviewed the overlap warning regarding #6447. Both PRs modify `tools/check_conventions.py`, but they address separate issues. PR #6447 modifies the conventions checker's handling of Markdown fences and other checks, while this PR adds error handling for failed Git subprocess calls. I also inspected the `git()` function in PR #6447 and confirmed that it retains the original implementation without `CalledProcessError` or `FileNotFoundError` handling. Based on this comparison, I found no duplicate implementation of the functionality introduced by this PR.
jotitadev commented 2026-10-18 11:28:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T11:28:35Z.

Review: COMMENTED


Checked on macOS, head 49c2feab7.

Machine: Apple M2 Max, macOS 27.2, Xcode's /usr/bin/python3 3.9.6 and Python 3.14.7.

  • tools/test_check_conventions_git.py passes on both Pythons. With main's check_conventions.py, both tests fail (a CalledProcessError traceback, exit 1), so they do cover the change.
  • By hand: an invalid --base or --head now prints Git command failed: fatal: Not a valid object name ... and exits 2.

The new test is not registered, so CI never runs it. The PR adds the file as tools/test_check_conventions_git.py and does not touch CMakeLists.txt. The other check_conventions tests live in tools/tests/ and each has an add_test entry there (conventions_ci_gate, conventions_doc_links, ...). Nothing in .github/workflows discovers loose tools/test_*.py files either: the only one run directly is test_web.py. Moving the file to tools/tests/ and adding an add_test(NAME conventions_git_errors ...) next to the others would get it into ctest.

Minor: the tests run check_conventions.py from the current directory and only check the Git command failed: prefix. Run outside a git checkout, they pass because of not a git repository, not because of the invalid revision. Asserting on this-branch-does-not-exist in stderr, or passing cwd set to the repository root, would pin that down.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5562736862 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7456#pullrequestreview-5562736862). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-18T11:28:35Z. **Review:** COMMENTED --- Checked on macOS, head `49c2feab7`. Machine: Apple M2 Max, macOS 27.2, Xcode's `/usr/bin/python3` 3.9.6 and Python 3.14.7. - `tools/test_check_conventions_git.py` passes on both Pythons. With `main`'s `check_conventions.py`, both tests fail (a `CalledProcessError` traceback, exit 1), so they do cover the change. - By hand: an invalid `--base` or `--head` now prints `Git command failed: fatal: Not a valid object name ...` and exits 2. **The new test is not registered, so CI never runs it.** The PR adds the file as `tools/test_check_conventions_git.py` and does not touch `CMakeLists.txt`. The other `check_conventions` tests live in `tools/tests/` and each has an `add_test` entry there (`conventions_ci_gate`, `conventions_doc_links`, ...). Nothing in `.github/workflows` discovers loose `tools/test_*.py` files either: the only one run directly is `test_web.py`. Moving the file to `tools/tests/` and adding an `add_test(NAME conventions_git_errors ...)` next to the others would get it into ctest. Minor: the tests run `check_conventions.py` from the current directory and only check the `Git command failed:` prefix. Run outside a git checkout, they pass because of `not a git repository`, not because of the invalid revision. Asserting on `this-branch-does-not-exist` in stderr, or passing `cwd` set to the repository root, would pin that down. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Cankiee commented 2026-10-18 15:11:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Cankiee on 2026-10-18T15:11:41Z.


Thanks for testing this on macOS and for the detailed feedback!

I've addressed both issues:

  • Moved the regression tests into tools/tests/.
  • Added conventions_git_errors to CMakeLists.txt so CTest can run them.
  • Set the subprocess working directory to the repository root.
  • Added an assertion for the invalid revision name to prevent false-positive test results.

The updated Python regression tests pass locally on Windows with Python 3.14.

Thanks again for the review!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251514197 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7456#issuecomment-6251514197). Originally posted by [Cankiee](https://github.com/Cankiee) on 2026-10-18T15:11:41Z. --- Thanks for testing this on macOS and for the detailed feedback! I've addressed both issues: - Moved the regression tests into `tools/tests/`. - Added `conventions_git_errors` to `CMakeLists.txt` so CTest can run them. - Set the subprocess working directory to the repository root. - Added an assertion for the invalid revision name to prevent false-positive test results. The updated Python regression tests pass locally on Windows with Python 3.14. Thanks again for the review!
github-actions[bot] commented 2026-10-18 15:33:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T15:33:28Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 674 CMakeLists.txt
PR 1835 CMakeLists.txt
PR 5021 CMakeLists.txt
PR 6044 CMakeLists.txt
PR 6879 CMakeLists.txt
PR 6946 CMakeLists.txt
PR 6947 CMakeLists.txt
PR 7201 CMakeLists.txt
PR 7332 CMakeLists.txt
PR 7523 CMakeLists.txt
PR 7642 CMakeLists.txt
PR 8161 CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251735107 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7456#issuecomment-6251735107). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T15:33:28Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 674](https://www.github.com/boykopovar/AnyPS5/pull/674) | `CMakeLists.txt` | | [PR 1835](https://www.github.com/boykopovar/AnyPS5/pull/1835) | `CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `CMakeLists.txt` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `CMakeLists.txt` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `CMakeLists.txt` | | [PR 6946](https://www.github.com/boykopovar/AnyPS5/pull/6946) | `CMakeLists.txt` | | [PR 6947](https://www.github.com/boykopovar/AnyPS5/pull/6947) | `CMakeLists.txt` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `CMakeLists.txt` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `CMakeLists.txt` | | [PR 7523](https://www.github.com/boykopovar/AnyPS5/pull/7523) | `CMakeLists.txt` | | [PR 7642](https://www.github.com/boykopovar/AnyPS5/pull/7642) | `CMakeLists.txt` | | [PR 8161](https://www.github.com/boykopovar/AnyPS5/pull/8161) | `CMakeLists.txt` |
jotitadev commented 2026-10-18 15:45:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T15:45:22Z.


Re-checked head 361f56a08 on macOS after the changes, merged with main e5f18ea99.

Machine: Apple M2 Max, macOS 27.2, Xcode's /usr/bin/python3 3.9.6 and Python 3.14.7.

  • conventions_git_errors is now registered and runs in ctest (relinker-only configure, x86_64 with Python 3.9.6): passes, together with test_registration.
  • tools/tests/test_check_conventions_git.py passes on both Pythons, also when started from outside the checkout. With main's check_conventions.py both tests fail, so they still cover the change.
  • check_conventions.py --base origin/main passes on the merge.

Both points from my earlier review are addressed.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251856134 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7456#issuecomment-6251856134). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-18T15:45:22Z. --- Re-checked head `361f56a08` on macOS after the changes, merged with `main` e5f18ea99. Machine: Apple M2 Max, macOS 27.2, Xcode's `/usr/bin/python3` 3.9.6 and Python 3.14.7. - `conventions_git_errors` is now registered and runs in ctest (relinker-only configure, x86_64 with Python 3.9.6): passes, together with `test_registration`. - `tools/tests/test_check_conventions_git.py` passes on both Pythons, also when started from outside the checkout. With `main`'s `check_conventions.py` both tests fail, so they still cover the change. - `check_conventions.py --base origin/main` passes on the merge. Both points from my earlier review are addressed. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Cankiee commented 2026-10-18 18:35:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Cankiee on 2026-10-18T18:35:43Z.


I manually checked the CMakeLists.txt overlap warnings against all 10 flagged PRs (#674, #1835, #3998, #5021, #5710, #6044, #6746, #6879, #7201 and #7332).

None of the PR diffs adds the conventions_git_errors registration or references test_check_conventions_git.py.

Thanks to @jotitadev for independently verifying the updated implementation and tests on macOS.

As far as I can tell, there is no duplicate implementation of this test registration. The remaining warnings appear to be caused by other changes to the shared CMakeLists.txt file.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253608089 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7456#issuecomment-6253608089). Originally posted by [Cankiee](https://github.com/Cankiee) on 2026-10-18T18:35:43Z. --- I manually checked the CMakeLists.txt overlap warnings against all 10 flagged PRs (#674, #1835, #3998, #5021, #5710, #6044, #6746, #6879, #7201 and #7332). None of the PR diffs adds the `conventions_git_errors` registration or references `test_check_conventions_git.py`. Thanks to @jotitadev for independently verifying the updated implementation and tests on macOS. As far as I can tell, there is no duplicate implementation of this test registration. The remaining warnings appear to be caused by other changes to the shared `CMakeLists.txt` file.
adriadam10 commented 2026-10-20 10:27:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T10:27:39Z.


The full Build failed conventions_git_errors on the relinker job: test_invalid_head_branch ran with the default --base origin/main, which does not exist in a CI checkout, so git rejected the base first and the message never named the invalid head. I pushed a small commit to your branch (rebased on current main): each test now passes HEAD for the option it is not testing. Both tests pass; the rest is as reviewed (the git() handling exits 2 with a readable message, and both tests fail on main); merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6288842446 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7456#issuecomment-6288842446). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-20T10:27:39Z. --- The full Build failed `conventions_git_errors` on the relinker job: `test_invalid_head_branch` ran with the default `--base origin/main`, which does not exist in a CI checkout, so git rejected the base first and the message never named the invalid head. I pushed a small commit to your branch (rebased on current main): each test now passes `HEAD` for the option it is not testing. Both tests pass; the rest is as reviewed (the `git()` handling exits 2 with a readable message, and both tests fail on `main`); merged.
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
boykopovar/AnyPS5!7456
No description provided.