{"record":{"id":"87215d2c7d5866e1","repo":"ZhuLinsen/daily_stock_analysis","slug":"unsupported-alert-type-for-current-eventmonitor-ru","errorCode":null,"errorMessage":"unsupported alert_type for current EventMonitor runtime: {alert_type.value} (supported: {_supported_alert_type_names()})","messagePattern":"unsupported alert_type for current EventMonitor runtime: (.+?) \\(supported: (.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"src/agent/events.py","lineNumber":68,"sourceCode":"    TRIGGERED = \"triggered\"\n    EXPIRED = \"expired\"\n    DISMISSED = \"dismissed\"\n\n\n_RUNTIME_SUPPORTED_ALERT_TYPES = frozenset({\n    AlertType.PRICE_CROSS,\n    AlertType.PRICE_CHANGE_PERCENT,\n    AlertType.VOLUME_SPIKE,\n})\n\n\ndef _supported_alert_type_names() -> str:\n    return \", \".join(sorted(alert_type.value for alert_type in _RUNTIME_SUPPORTED_ALERT_TYPES))\n\n\ndef _ensure_runtime_supported_alert_type(alert_type: AlertType) -> None:\n    if alert_type not in _RUNTIME_SUPPORTED_ALERT_TYPES:\n        raise ValueError(\n            f\"unsupported alert_type for current EventMonitor runtime: {alert_type.value} \"\n            f\"(supported: {_supported_alert_type_names()})\"\n        )\n\n\ndef _read_quote_float(quote: Any, *field_names: str) -> Optional[float]:\n    \"\"\"Read a numeric field from quote objects or dict-like payloads.\"\"\"\n    if quote is None:\n        return None\n\n    for field_name in field_names:\n        if isinstance(quote, dict):\n            raw_value = quote.get(field_name)\n        else:\n            raw_value = getattr(quote, field_name, None)\n\n        if raw_value is None and hasattr(quote, \"to_dict\"):\n            try:","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/src/agent/events.py#L50-L86","documentation":"_ensure_runtime_supported_alert_type guards AlertType values against _RUNTIME_SUPPORTED_ALERT_TYPES, a frozenset containing only PRICE_CROSS, PRICE_CHANGE_PERCENT and VOLUME_SPIKE. The AlertType enum defines more values (e.g. SENTIMENT_SHIFT at events.py:160), but the current EventMonitor runtime only implements checks for those three, so validating or evaluating any other alert type raises this ValueError naming the supported set.","triggerScenarios":"validate_event_alert_rule() (events.py:473-ish) constructs AlertType(rule['alert_type']) then immediately calls this guard: submitting a rule with alert_type='sentiment_shift' (a legal enum member) raises. Also any code path that calls _ensure_runtime_supported_alert_type directly.","commonSituations":"Configs or API payloads written against the fuller enum surface; a rule store persisted with a sentiment rule from an earlier/other runtime; users enabling alert kinds the monitor's evaluation loop never checks.","solutions":["Change the rule's alert_type to one of: price_change_percent, price_cross, volume_spike","If you need sentiment alerts, implement the evaluation branch in EventMonitor and add the value to _RUNTIME_SUPPORTED_ALERT_TYPES","Filter unsupported types out at load time and log, if you prefer degrade-over-fail for stored rules","Keep the enum and the runtime frozenset in sync when adding new alert types"],"exampleFix":"// before\nrule = {\"stock_code\": \"600519\", \"alert_type\": \"sentiment_shift\"}\nvalidate_event_alert_rule(rule)  # ValueError\n\n// after\nrule = {\"stock_code\": \"600519\", \"alert_type\": \"price_change_percent\", \"change_pct\": 5, \"direction\": \"up\"}\nvalidate_event_alert_rule(rule)","handlingStrategy":"validation","validationCode":"from src.agent.events import _RUNTIME_SUPPORTED_ALERT_TYPES, AlertType\n\ndef alert_type_supported(value: str) -> bool:\n    try:\n        return AlertType(value) in _RUNTIME_SUPPORTED_ALERT_TYPES\n    except ValueError:\n        return False","typeGuard":"from src.agent.events import AlertType, _RUNTIME_SUPPORTED_ALERT_TYPES\n\ndef is_supported_alert_type(value: str) -> bool:\n    try:\n        return AlertType(value) in _RUNTIME_SUPPORTED_ALERT_TYPES\n    except ValueError:\n        return False","tryCatchPattern":null,"preventionTips":["Whitelist alert types before persisting rules","Sync enum and supported set on changes","Surface the supported list in API errors"],"tags":["python","validation","alerts","enum","event-monitor"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}