At NovaFlow, a data pipeline script emits log lines for each processing step. Implement a function that scans these lines and returns a summary of exception activity by counting failed records, collecting unique error types, and preserving the order of the first occurrence of each error.
Given a list of strings logs, where each string is one log line, return a dictionary with:
failed_count: total number of lines that contain an exceptionerror_types: a list of unique exception names in first-seen orderlatest_message: the message text from the last exception line, or "" if none existA line is considered an exception line if it matches this format exactly:
ERROR:<ExceptionName>:<message>
<ExceptionName> contains only letters and ends with Error or Exception. The <message> part may contain spaces and punctuation.
logs — list of stringsfailed_count, error_types, and latest_messageExample 1
Input: logs = ["INFO:start", "ERROR:ValueError:bad row", "ERROR:TypeError:wrong type"]
Output: {"failed_count": 2, "error_types": ["ValueError", "TypeError"], "latest_message": "wrong type"}
Explanation: Two exception lines appear, both unique, and the last message is from the final error line.
Example 2
Input: logs = ["INFO:ok", "WARN:retry", "INFO:done"]
Output: {"failed_count": 0, "error_types": [], "latest_message": ""}
Explanation: No line matches the exception format.
1 <= len(logs) <= 10^40 <= len(logs[i]) <= 200logs = ["INFO:start", "ERROR:ValueError:bad row", "ERROR:TypeError:wrong type"]Output{"failed_count": 2, "error_types": ["ValueError", "TypeError"], "latest_message": "wrong type"}WhyBoth error lines are valid exceptions. The unique error types are recorded in encounter order, and the last error message is `wrong type`.logs = ["INFO:ok", "WARN:retry", "INFO:done"]Output{"failed_count": 0, "error_types": [], "latest_message": ""}WhyNo line starts with a valid `ERROR:<ExceptionName>:` pattern, so the summary is empty.logs = ["ERROR:ValueError:bad row", "ERROR:ValueError:bad schema", "ERROR:RuntimeException:crash"]Output{"failed_count": 3, "error_types": ["ValueError", "RuntimeException"], "latest_message": "crash"}WhyAll three lines are valid exceptions, but `ValueError` appears only once in the unique list.1 <= len(logs) <= 10^40 <= len(logs[i]) <= 200A valid exception line has the exact form `ERROR:<ExceptionName>:<message>``<ExceptionName>` contains only letters and ends with `Error` or `Exception`def summarize_pipeline_logs(logs):