ZhuLinsen/daily_stock_analysis · error · ValueError
validation_error
validation_error
Error message
unsupported market alert_type: {alert_type} What it means
ValueError(f'unsupported market alert_type: {alert_type}') with code validation_error is raised by normalize_market_alert_parameters (src/services/market_light_alerts.py:53) when the alert_type is not in MARKET_ALERT_TYPES = {'market_light_status', 'market_light_score_drop'}. It guards the market alert parameter normalization entry point before any type-specific parsing.
Source
Thrown at src/services/market_light_alerts.py:52
class MarketLightAlert:
"""Runtime alert for market-level Market Light rules."""
target_scope: str
target: str
alert_type: str
parameters: Dict[str, Any]
metadata: Dict[str, Any] = field(default_factory=dict)
description: str = ""
stock_code: str = ""
def __post_init__(self) -> None:
self.target = normalize_market_alert_region(self.target)
self.stock_code = self.target
def normalize_market_alert_parameters(alert_type: str, parameters: Dict[str, Any]) -> Dict[str, Any]:
if alert_type not in MARKET_ALERT_TYPES:
raise ValueError(f"unsupported market alert_type: {alert_type}")
if not isinstance(parameters, dict):
raise ValueError("parameters must be an object")
if alert_type == "market_light_status":
raw_statuses = parameters.get("statuses")
if raw_statuses is None:
raw_statuses = ["red", "yellow"]
if isinstance(raw_statuses, str):
raw_statuses = [raw_statuses]
if not isinstance(raw_statuses, list) or not raw_statuses:
raise ValueError("market_light_status statuses must be a non-empty list")
statuses = []
for raw_status in raw_statuses:
status = str(raw_status or "").strip().lower()
if status not in MARKET_STATUS_VALUES:
raise ValueError("market_light_status statuses only supports red or yellow")
if status not in statuses:
statuses.append(status)View on GitHub (pinned to 5159bd72e8)
Solutions
- Check the exact string being sent and compare with MARKET_ALERT_TYPES in src/services/market_light_alerts.py:21
- Use 'market_light_status' (red/yellow light changes) or 'market_light_score_drop' (score drop threshold) as the alert_type
- If a portfolio-style alert was intended, call the portfolio alert normalization (normalize_portfolio_alert_parameters) instead
- Sync frontend/API-client enums with the backend frozenset to prevent drift
Example fix
# before
normalize_market_alert_parameters("market_status", {"statuses": ["red"]})
# after
normalize_market_alert_parameters("market_light_status", {"statuses": ["red"]}) Defensive patterns
Strategy: type-guard
Validate before calling
from src.services.market_light_alerts import MARKET_ALERT_TYPES
if alert_type not in MARKET_ALERT_TYPES:
raise ValueError(f"choose from {sorted(MARKET_ALERT_TYPES)}") Type guard
from src.services.market_light_alerts import MARKET_ALERT_TYPES
def is_valid_market_alert_type(alert_type: str) -> bool:
return isinstance(alert_type, str) and alert_type in MARKET_ALERT_TYPES Try / catch
try:
params = normalize_market_alert_parameters(alert_type, parameters)
except ValueError as exc:
if "unsupported market alert_type" in str(exc):
return api_error(400, str(exc)) Prevention
- Drive frontend dropdowns from MARKET_ALERT_TYPES instead of hardcoding
- Import the frozenset constant rather than duplicating the list client-side
- Return 400 with the message so callers see the allowed values
When it happens
Trigger: Creating/updating a market alert whose alert_type is anything other than 'market_light_status' or 'market_score_drop'-family values — e.g. 'market_light', 'price_drop', typo'd strings, or a portfolio alert type passed to the market API.
Common situations: API clients sending outdated or renamed alert type strings after an upgrade, confusing portfolio alert types (portfolio_stop_loss etc.) with market alert types, or frontend enums drifting from backend constants.
Related errors
- parameters must be an object
- validation_error
- validation_error
- unsupported alert_type for current EventMonitor runtime: {al
- Event alert rules must be a JSON array
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/9c6cf77a86ab6f5a.
Report an issue: GitHub.