From 5e3d7f2d2938a857e7599a429a6cfabf3b12347b Mon Sep 17 00:00:00 2001 From: Olivier Cervello Date: Fri, 3 May 2024 11:28:47 +0200 Subject: [PATCH] fix(cli): catch JSON parse errors (#378) --- secator/cli.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/secator/cli.py b/secator/cli.py index 04f08494..3ea78115 100644 --- a/secator/cli.py +++ b/secator/cli.py @@ -561,14 +561,17 @@ def report_list(workspace): reports_dir = CONFIG.dirs.reports json_reports = reports_dir.glob("**/**/report.json") ws_reports = {} - for report in json_reports: - ws, runner, number = str(report).split('/')[-4:-1] + for path in json_reports: + ws, runner, number = str(path).split('/')[-4:-1] if ws not in ws_reports: ws_reports[ws] = [] - with open(report, 'r') as f: - content = json.loads(f.read()) - data = {'path': report, 'name': content['info']['name'], 'runner': runner} - ws_reports[ws].append(data) + with open(path, 'r') as f: + try: + content = json.loads(f.read()) + data = {'path': path, 'name': content['info']['name'], 'runner': runner} + ws_reports[ws].append(data) + except json.JSONDecodeError as e: + console.print(f'[bold red]Could not load {path}: {str(e)}') for ws in ws_reports: if workspace and not ws == workspace: