From c1b4eb2001d2e91477b550a449368a342db0050e Mon Sep 17 00:00:00 2001 From: JohnM Date: Fri, 9 Oct 2026 16:23:29 +0800 Subject: [PATCH] fix(tools): exit 2 when import_audit cannot read an input or write --json Co-Authored-By: Claude Opus 5.5 --- tools/import_audit.py | 3 +++ tools/tests/test_import_audit.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/tools/import_audit.py b/tools/import_audit.py index ea046eab5..25d6f611b 100644 --- a/tools/import_audit.py +++ b/tools/import_audit.py @@ -312,6 +312,9 @@ def main(argv=None): except AuditError as error: print(f"FAIL: {error}", file=sys.stderr) return 2 + except OSError as error: + print(f"FAIL: {error.strerror}: {error.filename}" if error.filename else f"FAIL: {error}", file=sys.stderr) + return 2 print(render(summary, records, missing)) return 1 if summary["unique_by_class"]["absent"] or missing else 0 diff --git a/tools/tests/test_import_audit.py b/tools/tests/test_import_audit.py index 860a5b9e5..2242cae3c 100644 --- a/tools/tests/test_import_audit.py +++ b/tools/tests/test_import_audit.py @@ -273,6 +273,22 @@ class ImportAuditTests(unittest.TestCase): self.assertEqual((code, out), (2, "")) self.assertIn("game.json: entry 0 has an invalid NID 'short'", err) + def test_unreadable_library_and_unwritable_json_exit_two(self): + work = self.work + library = work.libs / "libSceA.prx" + library.write_bytes(exporting("AAAAAAAAAAA")) + registry = work.root / "game.json" + write_registry(registry, [("AAAAAAAAAAA", "libSceA.prx")]) + code, out, err = work.run(registry, "--json", str(work.modules)) + self.assertEqual((code, out), (2, "")) + self.assertIn("FAIL: ", err) + self.assertIn(str(work.modules), err) + denied = PermissionError(13, "Permission denied", str(library)) + with patch.object(Path, "read_bytes", side_effect=denied): + code, out, err = work.run(registry) + self.assertEqual((code, out), (2, "")) + self.assertIn(f"FAIL: Permission denied: {library}", err) + if __name__ == "__main__": unittest.main()