From 395910ed2b48abfb5a287a1d699f9fa419e224d8 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Fri, 6 Nov 2026 14:45:26 +0100 Subject: [PATCH] fix: one-line errors for --record-coreinfo --- scripts/check_freshness.py | 12 ++++++++++-- tests/test_check_freshness.py | 19 +++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/scripts/check_freshness.py b/scripts/check_freshness.py index d5b0df8c9..f83c84588 100644 --- a/scripts/check_freshness.py +++ b/scripts/check_freshness.py @@ -54,11 +54,13 @@ import pin_installer # noqa: E402 import refresh_data_dirs # noqa: E402 import upstream # noqa: E402 from common import ( # noqa: E402 + InputMissing, apply_target_overrides, list_registered_platforms, load_emulator_profiles, load_platform_registry, require_directory, + suggest_names, upstream_profile_index, write_text_atomic, yaml_load, @@ -893,7 +895,10 @@ def record_core_info( """ unknown = sorted(set(names) - set(blobs)) if unknown: - raise ValueError(f"no such .info in core-info: {', '.join(unknown)}") + raise InputMissing( + f"no such .info in core-info: {', '.join(unknown)}. " + + suggest_names(unknown, list(blobs), "libretro-core-info") + ) recorded = load_core_info_record(path) or {} recorded.update({n: blobs[n] for n in (names or blobs)}) payload = {"repository": CORE_INFO_REPO, "blobs": dict(sorted(recorded.items()))} @@ -1839,7 +1844,10 @@ def main() -> int: if args.record_coreinfo is not None: blobs = core_info_blobs(args.cache_dir, args.offline) if not blobs: - raise RuntimeError("core-info listing unavailable: nothing recorded") + raise InputMissing( + f"core-info listing not in {args.cache_dir}: run without --offline" + if args.offline else "core-info listing unavailable: the GitHub API did not answer" + ) done = record_core_info(blobs, args.record_coreinfo) print(f"recorded {len(done)} .info file(s) as reviewed") return 0 diff --git a/tests/test_check_freshness.py b/tests/test_check_freshness.py index 829062f66..a7bd3d078 100644 --- a/tests/test_check_freshness.py +++ b/tests/test_check_freshness.py @@ -316,8 +316,23 @@ class CoreResolutionTests(unittest.TestCase): record.write_text(cf.json.dumps({"blobs": {"a": "1", "b": "1"}})) cf.record_core_info({"a": "2", "b": "2"}, ["a"], record) self.assertEqual(cf.load_core_info_record(record), {"a": "2", "b": "1"}) - with self.assertRaises(ValueError): - cf.record_core_info({"a": "2"}, ["ghost"], record) + with self.assertRaises(cf.InputMissing) as raised: + cf.record_core_info({"a": "2", "ghosts": "1"}, ["ghost"], record) + self.assertIn("Did you mean: ghosts?", str(raised.exception)) + + def test_record_errors_are_one_line(self): + """A mistyped core and an empty offline cache ended on a traceback.""" + import subprocess # noqa: PLC0415 + + with tempfile.TemporaryDirectory() as tmp: + proc = subprocess.run( + [sys.executable, str(REPO_ROOT / "scripts" / "check_freshness.py"), "--offline", + "--cache-dir", tmp, "--record-coreinfo"], + capture_output=True, text=True, check=False, timeout=120, + ) + self.assertEqual(proc.returncode, 1) + self.assertNotIn("Traceback", proc.stderr) + self.assertIn("run without --offline", proc.stderr) def test_offline_without_a_cached_listing_is_skipped(self): """Offline, the row read UNKNOWN and failed the run as an upstream