wpt: Ensure that faulty JSON testharness output does not crash the Python test harness (#38420)

When a testharness test also prints debugging output, sometimes the
output can be mixed with the JSON output printed via an alert. This
causes a JSON decoding error in the output. Instead of crashing the
harness and printing many lines of Python stack trace output, print a
nice error. This makes the test output easier to read.

Testing: This is a change to the test harness itself, so no tests
necessary.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-08-02 15:04:17 +02:00 committed by GitHub
parent 58425f6ae2
commit 181f97879d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 2 deletions

View file

@ -521535,7 +521535,7 @@
[]
],
"executorservo.py": [
"7b0a64a60489f91fe2d2ec92c69118c0b5b1b8c0",
"d983cf048ed6dfe1c07fdcac4f3465f116a00c58",
[]
],
"executorservodriver.py": [

View file

@ -173,7 +173,10 @@ class ServoTestharnessExecutor(ServoExecutor):
prefix = "ALERT: RESULT: "
decoded_line = line.decode("utf8", "replace")
if decoded_line.startswith(prefix):
self.result_data = json.loads(decoded_line[len(prefix):])
try:
self.result_data = json.loads(decoded_line[len(prefix):])
except json.JSONDecodeError as error:
self.logger.error(f"Could not process test output JSON: {error}")
self.result_flag.set()
else:
ServoExecutor.on_output(self, line)