fix(CORE-001D3B): reject malformed alert history entries
This commit is contained in:
@@ -67,7 +67,18 @@ class AlertHistoryRepository:
|
||||
raise AlertHistoryLoadError(self.history_path, f"Alert history could not be read: {exc}") from exc
|
||||
if not isinstance(data, list):
|
||||
raise AlertHistoryLoadError(self.history_path, "Alert history payload must be a list")
|
||||
return [AlertEvent.from_dict(item) for item in data if isinstance(item, dict)]
|
||||
events: list[AlertEvent] = []
|
||||
for index, item in enumerate(data):
|
||||
if not isinstance(item, dict):
|
||||
raise AlertHistoryLoadError(self.history_path, f"Alert history entry {index} must be an object")
|
||||
try:
|
||||
events.append(AlertEvent.from_dict(item))
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise AlertHistoryLoadError(
|
||||
self.history_path,
|
||||
f"Alert history entry {index} is invalid: {exc}",
|
||||
) from exc
|
||||
return events
|
||||
|
||||
def save(self, events: list[AlertEvent]) -> None:
|
||||
with self.history_path.open("w") as f:
|
||||
|
||||
Reference in New Issue
Block a user