IndexError when scan has no results in get_results_csv() and get_logs_csv()
get_results_csv() and get_logs_csv() in nettacker/api/engine.py access data[0].keys() to build CSV fieldnames without checking if data is empty. When a scan has no results (empty list), this raises an unhandled IndexError instead of returning a clean error response.
data = get_logs_by_scan_id(scan_details.scan_unique_id) keys = data[0].keys() # IndexError if data is empty
Originally noted by @mason5052 in a comment on #1247, but this is a separate code path from the path-corruption fix in PR #1248 — that PR doesn't touch the empty-data case. I also checked PR #1151 (Windows compatibility) — it reworks path/filename handling in engine.py but does not address this empty-list check either.
Suggested fix:
if not data: return jsonify(structure(status="error", msg="No scan data found")), 404
Add before data[0].keys() in both functions.
I'd like to work on this — happy to add a regression test for a scan ID with no results. @securestep9