fix: refuse a mistyped --target in cross_reference

load_target_config raised out of cross_reference.py as a traceback. The hint now names the full verify.py command, since cross_reference and slots have no --list-targets.
This commit is contained in:
Abdessamad Derraz committed 2026-10-21 10:00:47 +02:00
1 parent 8ed1a737a8
commit 7b9c8ae663
3 files changed
+33 -6

No files matched your search

+4 -1
View File
@@ -658,8 +658,11 @@ def load_target_config(
# through, where a platform or emulator name gets the closest ones.
raise ValueError(
f"Unknown target '{target}' for platform '{platform_name}'.\n"
# Named as a full command: cross_reference.py and slots.py take
# --target but have no --list-targets of their own.
+ suggest_names(
[target], sorted(alias_index), "--list-targets", len(targets)
[target], sorted(alias_index),
f"verify.py --platform {platform_name} --list-targets", len(targets),
)
)
+10 -5
View File
@@ -979,11 +979,16 @@ def main() -> None:
if args.platform:
from common import load_target_config, resolve_platform_cores
target_cores = (
load_target_config(args.platform, args.target, args.platforms_dir)
if args.target
else None
)
try:
target_cores = (
load_target_config(args.platform, args.target, args.platforms_dir)
if args.target
else None
)
except (FileNotFoundError, ValueError) as exc:
# A typo ended in a traceback where verify and slots name the
# closest target.
parser.error(str(exc))
config = load_platform_config(args.platform, args.platforms_dir)
relevant = resolve_platform_cores(config, profiles, target_cores=target_cores)
run_anywhere = (
+19
View File
@@ -6277,5 +6277,24 @@ class ExternalDownloadsFollowTheRunPolicy(unittest.TestCase):
self.assertIn("dir=", call)
class ATargetTypoIsAnErrorInEveryTool(unittest.TestCase):
"""cross_reference.py ended a mistyped --target in a traceback, and the
hint sent cross_reference and slots users to a flag they do not have."""
def test_each_tool_names_the_closest_target(self):
for script in ("cross_reference.py", "slots.py", "verify.py"):
with self.subTest(script=script):
proc = subprocess.run(
[sys.executable, f"scripts/{script}", "--platform", "retroarch",
"--target", "swich"],
cwd=ROOT, capture_output=True, text=True, timeout=300,
)
output = proc.stdout + proc.stderr
self.assertNotEqual(proc.returncode, 0)
self.assertNotIn("Traceback", output)
self.assertIn("Did you mean: switch?", output)
self.assertIn("verify.py --platform retroarch --list-targets", output)
if __name__ == "__main__":
unittest.main()