Skip to content

Commit 83f8147

Browse files
committed
Handle non-JSON xcresult references gracefully
1 parent b9bfafe commit 83f8147

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

scripts/ios/export_xcresult_attachments.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,43 @@ def ri_log(message: str) -> None:
1717
print(f"[run-ios-ui-tests] {message}", file=sys.stderr)
1818

1919

20-
def run_xcresult(args: Sequence[str]) -> str:
20+
def run_xcresult(args: Sequence[str], allow_failure: bool = False) -> Optional[str]:
2121
cmd = ["xcrun", "xcresulttool", *args]
22-
try:
23-
result = subprocess.run(
22+
result = subprocess.run(
23+
cmd,
24+
check=False,
25+
stdout=subprocess.PIPE,
26+
stderr=subprocess.PIPE,
27+
)
28+
if result.returncode != 0:
29+
stderr = result.stderr.decode("utf-8", "ignore").strip()
30+
ri_log(f"xcresulttool command failed: {' '.join(cmd)}\n{stderr}")
31+
if allow_failure:
32+
return None
33+
raise subprocess.CalledProcessError(
34+
result.returncode,
2435
cmd,
25-
check=True,
26-
stdout=subprocess.PIPE,
27-
stderr=subprocess.PIPE,
36+
output=result.stdout,
37+
stderr=result.stderr,
2838
)
29-
except subprocess.CalledProcessError as exc:
30-
stderr = exc.stderr.decode("utf-8", "ignore").strip()
31-
ri_log(f"xcresulttool command failed: {' '.join(cmd)}\n{stderr}")
32-
raise
3339
return result.stdout.decode("utf-8")
3440

3541

3642
def get_json(bundle_path: str, object_id: Optional[str] = None) -> Dict:
3743
args = ["get", "--legacy", "--path", bundle_path, "--format", "json"]
3844
if object_id:
3945
args.extend(["--id", object_id])
40-
output = run_xcresult(args)
41-
return json.loads(output or "{}")
46+
output = run_xcresult(args, allow_failure=True)
47+
if not output:
48+
return {}
49+
try:
50+
return json.loads(output)
51+
except json.JSONDecodeError:
52+
ri_log(
53+
"Failed to decode xcresult JSON payload; "
54+
"continuing without structured data"
55+
)
56+
return {}
4257

4358

4459
def extract_id(ref: object) -> Optional[str]:

0 commit comments

Comments
 (0)