From 21893f38d0ffd24990881c6930b58332bf62a515 Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Mon, 29 Jun 2026 17:58:15 -0400 Subject: [PATCH] fix(scripts): gracefully handle malformed JSON in api_diff_report --- scripts/api_diff_report/api_diff_report.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/api_diff_report/api_diff_report.py b/scripts/api_diff_report/api_diff_report.py index 4ec6a6ddef2..6c085c10d8b 100644 --- a/scripts/api_diff_report/api_diff_report.py +++ b/scripts/api_diff_report/api_diff_report.py @@ -35,13 +35,21 @@ def main(): old_api_file = os.path.join(os.path.expanduser(args.base_branch), api_info.API_INFO_FILE_NAME) if os.path.exists(new_api_file): - with open(new_api_file) as f: - new_api_json = json.load(f) + try: + with open(new_api_file) as f: + new_api_json = json.load(f) + except json.JSONDecodeError as e: + logging.error(f'Error parsing JSON from {new_api_file}: {e}') + new_api_json = {} else: new_api_json = {} if os.path.exists(old_api_file): - with open(old_api_file) as f: - old_api_json = json.load(f) + try: + with open(old_api_file) as f: + old_api_json = json.load(f) + except json.JSONDecodeError as e: + logging.error(f'Error parsing JSON from {old_api_file}: {e}') + old_api_json = {} else: old_api_json = {}