Spaces:
Sleeping
Sleeping
File size: 1,159 Bytes
cc8beab 6710fbe cc8beab | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | from __future__ import annotations
from datetime import datetime, timezone
from typing import Any, Dict, Optional
from src.core.FinanceState import FinanceState
def add_error(
state: FinanceState,
*,
code: str,
message: str,
agent: Optional[str] = None,
detail: Optional[Dict[str, Any]] = None,
) -> None:
"""
Append a normalized error entry into state["errors"].
This is best-effort telemetry for UI/debugging; it should never raise.
"""
try:
entry: Dict[str, Any] = {
"ts": datetime.now(timezone.utc).isoformat(),
"code": code,
"message": message,
}
trace_id = state.get("trace_id")
if isinstance(trace_id, str) and trace_id:
entry["trace_id"] = trace_id
if agent:
entry["agent"] = agent
if detail:
entry["detail"] = detail
errors = state.get("errors")
if not isinstance(errors, list):
errors = []
errors.append(entry)
state["errors"] = errors
except Exception:
# Never allow telemetry to break the user experience.
return
|