fix(tools): exit 2 when import_audit cannot read an input or write --json

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
JohnM
2026-10-09 16:23:29 +08:00
parent d70b899894
commit c1b4eb2001
2 changed files with 19 additions and 0 deletions
+3
View File
@@ -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
+16
View File
@@ -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()