Reporting Every Bad Row With AggregateError
The trustees’ rule is all or nothing: if any row of an export is bad, nothing is imported, and
the report lists every bad row at once. So Python’s import_month() collects each BadRowError
in a list, problems, and raises them together as an ExceptionGroup, a message and then the
list:
if problems:
message = f"{len(problems)} bad rows in {path}"
raise ExceptionGroup(message, problems)
main() catches the group with except* and prints the group’s message, then each bad row:
except* BadRowError as group:
print(f"Nothing imported: {group.message}")
for err in group.exceptions:
print(f" {err}")
For november.csv, the script prints four lines and exits with 1: