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 <jerensslensun@gmail.com>
This commit is contained in:
Jerens Lensun 2025-07-29 15:00:07 +08:00 committed by GitHub
parent 554b2da1ad
commit 239bdd7c1a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View file

@ -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=" "))

View file

@ -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):