mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:08:38 +00:00
gen_bcpack_runtime_tables: limit TypeError/KeyError catch to --profile path
This commit is contained in:
@ -146,5 +146,16 @@ class GenBcpackRuntimeTablesTests(unittest.TestCase):
|
||||
self.assertEqual(sorted(os.listdir(tmp)), ["cal.json", "profile.bin"])
|
||||
|
||||
|
||||
def test_generate_bugs_propagate_instead_of_exiting_2(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
out_inc = os.path.join(tmp, "out.inc")
|
||||
for exc in (TypeError("internal bug"), KeyError("missing_key")):
|
||||
with self.subTest(exc=type(exc).__name__):
|
||||
with mock.patch.object(gen, "generate", side_effect=exc):
|
||||
with self.assertRaises(type(exc)):
|
||||
gen.main([out_inc])
|
||||
self.assertFalse(os.path.exists(out_inc))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@ -157,14 +157,23 @@ def main(argv=None) -> int:
|
||||
parser.error("cannot combine positional output with --profile")
|
||||
if not args.profile and not args.output:
|
||||
parser.error("name the tables file to write, or use --profile")
|
||||
try:
|
||||
if args.profile:
|
||||
if args.profile:
|
||||
try:
|
||||
write_profile(*args.profile)
|
||||
else:
|
||||
except (OSError, ValueError, KeyError, TypeError, RecursionError) as e:
|
||||
print(f"gen_bcpack_runtime_tables: {e}", file=sys.stderr)
|
||||
return 2
|
||||
else:
|
||||
try:
|
||||
_validate_output_path(args.output, "output")
|
||||
except ValueError as e:
|
||||
print(f"gen_bcpack_runtime_tables: {e}", file=sys.stderr)
|
||||
return 2
|
||||
try:
|
||||
_atomic_write(args.output, generate, binary=False, label="output")
|
||||
except (OSError, ValueError, KeyError, TypeError, RecursionError) as e:
|
||||
print(f"gen_bcpack_runtime_tables: {e}", file=sys.stderr)
|
||||
return 2
|
||||
except OSError as e:
|
||||
print(f"gen_bcpack_runtime_tables: {e}", file=sys.stderr)
|
||||
return 2
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user