Report incomplete evidence honestly
Distinguish a successful empty collection from a missing or partly damaged export.
No events is not the same as no evidence
A detector can return no findings because it found no suspicious events, because the export was empty, or because collection failed. Those outcomes need different explanations. Carry a collection status alongside the event data instead of hiding every failure behind an empty list.
The supplied event_reader.py contains the validated reader from the first lesson. Import it so this task can focus on coordinating multiple sources. A complete source may legitimately accept zero events. A partial source has rejected lines. A missing source could not be read because the expected file is absent.
Preserve enough provenance to retry
Attach the source path to accepted events and errors, and retain the accepted count for each requested source. Use line zero for a missing file because no physical record was read. Keep requested-source order and each source's original record order.
This lesson treats each requested export as optional evidence and returns a partial collection. The capstone instead has required case inputs and fails if they are missing. Both policies are useful; the important part is stating which one a tool implements.
The helper may raise unexpected errors, such as a decoding failure. Do not catch every exception and label it an empty source. Let the caller see a genuine failure so it can retry or correct the input. Clear limits make an investigation report more trustworthy than an unexplained success message.
from event_reader import read_events
events, errors = read_events("events.jsonl")
print("Accepted:", len(events), "Rejected:", len(errors))
Put it into practice.
Use supplied event_reader.read_events to define collect_sources(paths). Return events, errors and sources lists. Add source to each accepted event and error. For existing sources report {source, status: "complete" or "partial", accepted}; partial means rejected lines exist, and a valid empty file is complete. Missing files produce status missing, accepted 0, and {source, line: 0, reason: "missing file"}. Preserve source and record order. Do not swallow other failures.
See an explained solution
from pathlib import Path
from event_reader import read_events
def collect_sources(paths):
events, errors, sources = [], [], []
for path in paths:
if not Path(path).is_file():
sources.append({"source": path, "status": "missing", "accepted": 0})
errors.append({"source": path, "line": 0, "reason": "missing file"})
continue
good, rejected = read_events(path)
status = "partial" if rejected else "complete"
sources.append({"source": path, "status": status, "accepted": len(good)})
events.extend({**event, "source": path} for event in good)
errors.extend({"source": path, **error} for error in rejected)
return {"events": events, "errors": errors, "sources": sources}
Collection status travels with the data, so no-findings cannot conceal missing evidence. The helper is reused without duplicating its parsing rules.