Skip to content

Commit 4530788

Browse files
committed
fix(scripts/get-rawprogram): in case of error, return gracefully
Return None when the input XML does not contain a rootfs entry or when parsing fails, instead of erroring out. This allows callers to distinguish between valid matches and missing data gracefully. Signed-off-by: Vishwas Udupa <vudupa@qti.qualcomm.com>
1 parent c45e2ae commit 4530788

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

scripts/get-rawprogram-filename.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@
1616

1717
if len(sys.argv) != 3:
1818
print(f"Usage: {sys.argv[0]} <label> <rawprogram0.xml>", file=sys.stderr)
19-
sys.exit(1)
19+
print("none")
20+
else:
21+
label, xml_file = sys.argv[1], sys.argv[2]
2022

21-
label, xml_file = sys.argv[1], sys.argv[2]
22-
23-
root = ET.parse(xml_file).getroot()
24-
e = root.find(f".//program[@label='{label}']")
25-
if e is None:
26-
print(f"error: no <program label='{label}'> found in {xml_file}",
27-
file=sys.stderr)
28-
sys.exit(1)
29-
30-
filename = e.get("filename")
31-
# Strip any leading ../ path components
32-
while filename.startswith("../"):
33-
filename = filename[3:]
34-
print(filename)
23+
root = ET.parse(xml_file).getroot()
24+
e = root.find(f".//program[@label='{label}']")
25+
if e is None:
26+
print("none")
27+
else:
28+
filename = e.get("filename")
29+
# Strip any leading ../ path components
30+
while filename.startswith("../"):
31+
filename = filename[3:]
32+
print(filename)

0 commit comments

Comments
 (0)