Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): catch JSON parse errors #378

Merged
merged 1 commit into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions secator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading