0

[fuchsia] Guard against unexpected format of product_bundle.json in update_product_bundles.py

In some infra builds, we have observed an empty manifest.json file. This is unexpected, and it's unclear where the empty file stems from. It's potentially a problem during checkout, but could also be incorrect cleanup in between infrastructure runs.

This CL aim to catch all unexpected situation when trying to read the
key "product_version" from product_bundle.json in JSON format.

Change-Id: I4f1b5a13df48b2e1ad4d9592bea2a50c4634ad1a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6228660
Reviewed-by: Zijie He <zijiehe@google.com>
Commit-Queue: YJ Wang <wangyj@google.com>
Reviewed-by: David Song <wintermelons@google.com>
Cr-Commit-Position: refs/heads/main@{#1415962}
This commit is contained in:
YJ Wang
2025-02-04 18:49:28 -08:00
committed by Chromium LUCI CQ
parent 0a0ff50055
commit 63b085a786

@ -106,7 +106,15 @@ def get_current_signature(image_dir):
version_file = os.path.join(image_dir, 'product_bundle.json')
if os.path.exists(version_file):
with open(version_file) as f:
return json.load(f)['product_version']
try:
data = json.load(f)
except json.decoder.JSONDecodeError:
logging.warning('product_bundle.json is not at the JSON format and may be empty.')
return None
if 'product_version' not in data:
logging.warning('The key "product_version" does not exist in product_bundle.json')
return None
return data['product_version']
return None