{"record":{"id":"0ea161f19cb6dcdf","repo":"ZhuLinsen/daily_stock_analysis","slug":"validation-error-0ea161","errorCode":"validation_error","errorMessage":"market target must be one of cn, hk, us, jp, kr: {region}","messagePattern":"market target must be one of cn, hk, us, jp, kr: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"src/services/market_light_service.py","lineNumber":28,"sourceCode":"from sqlalchemy import desc\n\nfrom src.core.market_review import MARKET_REVIEW_HISTORY_CODE, MARKET_REVIEW_REPORT_TYPE\nfrom src.market_analyzer import MarketAnalyzer\nfrom src.schemas.market_light import MarketLightSnapshot\nfrom src.storage import AnalysisHistory, DatabaseManager\n\n\nlogger = logging.getLogger(__name__)\n\nMARKET_LIGHT_REGIONS = frozenset({\"cn\", \"hk\", \"us\", \"jp\", \"kr\"})\nMARKET_LIGHT_ALERT_REGIONS = frozenset({\"cn\", \"hk\", \"us\"})\nMARKET_LIGHT_HISTORY_BATCH_SIZE = 100\n\n\ndef normalize_market_region(region: str) -> str:\n    value = str(region or \"\").strip().lower()\n    if value not in MARKET_LIGHT_REGIONS:\n        raise ValueError(f\"market target must be one of cn, hk, us, jp, kr: {region}\")\n    return value\n\n\ndef normalize_market_alert_region(region: str) -> str:\n    value = str(region or \"\").strip().lower()\n    if value not in MARKET_LIGHT_ALERT_REGIONS:\n        raise ValueError(f\"market alert target must be one of cn, hk, us: {region}\")\n    return value\n\n\ndef build_current_snapshot(region: str) -> Dict[str, Any]:\n    \"\"\"Build the current structured Market Light snapshot without LLM review.\"\"\"\n\n    normalized_region = normalize_market_region(region)\n    analyzer = MarketAnalyzer(region=normalized_region)\n    overview = analyzer.get_market_overview()\n    return analyzer.build_market_light_snapshot(overview)\n","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/src/services/market_light_service.py#L10-L46","documentation":"ValueError(f'market target must be one of cn, hk, us, jp, kr: {region}') with code validation_error is raised by normalize_market_region (src/services/market_light_service.py:24) when the requested market region, after strip().lower(), is not in MARKET_LIGHT_REGIONS = {'cn','hk','us','jp','kr'}. This is the entry-point validation for building/loading Market Light snapshots.","triggerScenarios":"Calling build_current_snapshot or snapshot-loading helpers with region values like 'a', 'CN ' (fine after trim), 'sh', 'china', 'gb', or an empty string/None (str(None) -> 'none').","commonSituations":"Passing stock-exchange codes instead of region codes, localized country names ('日本'), or regions added in a newer version being sent to an older deployment.","solutions":["Use one of the five supported region codes: cn, hk, us, jp, kr (case-insensitive, whitespace tolerated)","Map upstream market identifiers to these codes before calling (e.g. 'SHA'/'Shanghai' -> 'cn')","If you need another region, extend MARKET_LIGHT_REGIONS and the analyzer support deliberately — not by bypassing the check"],"exampleFix":"# before\nbuild_current_snapshot(\"china\")\n\n# after\nbuild_current_snapshot(\"cn\")","handlingStrategy":"type-guard","validationCode":"from src.services.market_light_service import MARKET_LIGHT_REGIONS\n\nregion = region.strip().lower()\nif region not in MARKET_LIGHT_REGIONS:\n    raise ValueError(f\"region must be one of {sorted(MARKET_LIGHT_REGIONS)}\")","typeGuard":"from src.services.market_light_service import MARKET_LIGHT_REGIONS\n\ndef is_supported_market_region(region: str) -> bool:\n    return isinstance(region, str) and region.strip().lower() in MARKET_LIGHT_REGIONS","tryCatchPattern":"try:\n    snapshot = build_current_snapshot(region)\nexcept ValueError as exc:\n    if \"market target must be one of\" in str(exc):\n        return api_error(400, \"supported regions: cn, hk, us, jp, kr\")","preventionTips":["Normalize region codes (strip/lower) before calling","Maintain a mapping from exchange/country identifiers to the five region codes","Source region pickers from MARKET_LIGHT_REGIONS"],"tags":["validation","market-data","region","api-contract"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}