From 239bdd7c1a12f7bdb5da2c20f4f5226c4a9294e9 Mon Sep 17 00:00:00 2001 From: Jerens Lensun <54782057+jerensl@users.noreply.github.com> Date: Tue, 29 Jul 2025 15:00:07 +0800 Subject: [PATCH] mach: Fail on invalid argument in try_parser (#38324) This will block the command, print an error message about an invalid argument being passed to the ./mach try command, and return the exit code. Testing: `./mach try test-wpt` Fixes: #38193 Signed-off-by: Jerens Lensun --- python/servo/testing_commands.py | 6 +++++- python/servo/try_parser.py | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py index 1fa0da5ff87..5fdc3b9b0db 100644 --- a/python/servo/testing_commands.py +++ b/python/servo/testing_commands.py @@ -808,7 +808,11 @@ class MachCommands(CommandBase): return 1 try_string = " ".join(try_strings) - config = servo.try_parser.Config(try_string) + try: + config = servo.try_parser.Config(try_string) + except ValueError as err: + print(f"Failed to parse `try` config because of {err}") + return 1 print(f"Trying on {remote} ({remote_url}) with following configuration:") print() print(textwrap.indent(config.to_json(indent=2), prefix=" ")) diff --git a/python/servo/try_parser.py b/python/servo/try_parser.py index 5dea810667c..e0456e411f4 100644 --- a/python/servo/try_parser.py +++ b/python/servo/try_parser.py @@ -197,6 +197,7 @@ class Config(object): input = "full" words: list[str] = input.split(" ") + invalid_words: list[str] = list() for word in words: # Handle keywords. @@ -220,10 +221,14 @@ class Config(object): job = handle_preset(word) job = handle_modifier(job, word) if job is None: + invalid_words.append(word) print(f"Ignoring unknown preset {word}") else: self.add_or_merge_job_to_matrix(job) + if len(invalid_words) > 0: + raise ValueError(f"Invalid `try` argument: {', '.join(invalid_words)}") + def add_or_merge_job_to_matrix(self, job: JobConfig) -> None: for existing_job in self.matrix: if existing_job.merge(job):