{"record":{"id":"c45828b6d6648fe6","repo":"ZhuLinsen/daily_stock_analysis","slug":"invalid-field-name-value","errorCode":null,"errorMessage":"invalid {field_name}: {value}","messagePattern":"invalid (.+?): (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"src/services/alert_indicators.py","lineNumber":380,"sourceCode":"            f\"{alert_type} periods require {required_bars} bars, \"\n            f\"but at most {MAX_REQUESTED_DAYS} days can be requested\"\n        )\n    return params\n\n\ndef _direction(value: Any, allowed: frozenset[str], *, default: str) -> str:\n    direction = str(value or default).strip().lower()\n    if direction not in allowed:\n        raise ValueError(f\"invalid direction: {direction}\")\n    return direction\n\n\ndef _int_in_range(value: Any, field_name: str, *, default: int, minimum: int = 2, maximum: int = 250) -> int:\n    raw_value = default if value is None or value == \"\" else value\n    try:\n        number = int(raw_value)\n    except (TypeError, ValueError) as exc:\n        raise ValueError(f\"invalid {field_name}: {value}\") from exc\n    if str(raw_value).strip() not in {str(number), f\"{number}.0\"}:\n        raise ValueError(f\"{field_name} must be an integer\")\n    if number < minimum or number > maximum:\n        raise ValueError(f\"{field_name} must be between {minimum} and {maximum}\")\n    return number\n\n\ndef _finite_float(value: Any, field_name: str) -> float:\n    try:\n        number = float(value)\n    except (TypeError, ValueError) as exc:\n        raise ValueError(f\"invalid {field_name}: {value}\") from exc\n    if not isfinite(number):\n        raise ValueError(f\"{field_name} must be finite\")\n    return number\n\n\ndef _float_in_range(","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/src/services/alert_indicators.py#L362-L398","documentation":"Raised by _int_in_range (src/services/alert_indicators.py:380) when a numeric field (window, period, fast_period, slow_period, signal_period, k_period, d_period) cannot be converted with int() at all — the except (TypeError, ValueError) branch. This is the 'not a number' case, distinct from the 'number but not integer-formatted' and 'out of range' cases.","triggerScenarios":"parameters like {\"period\": \"twelve\"}, {\"period\": \"12a\"}, {\"period\": None-with-no-default?} — note None and \"\" take the default instead — or {\"period\": [12]} / {\"period\": {\"v\": 12}} where int() raises TypeError on list/dict.","commonSituations":"Free-text form inputs instead of number inputs; JSON payload passing nested objects for a scalar field; localized number strings (\"12,5\") or currency symbols surviving from a UI.","solutions":["Send plain integers (or numeric strings like \"12\") for period-like fields.","Use a number input / parseInt on the frontend so non-numeric text cannot be submitted.","Leave the field absent or empty to take the documented default rather than sending junk."],"exampleFix":"// before\n{ \"alert_type\": \"rsi_threshold\", \"parameters\": { \"period\": \"14天\", \"threshold\": 70 } }\n\n// after\n{ \"alert_type\": \"rsi_threshold\", \"parameters\": { \"period\": 14, \"threshold\": 70 } }","handlingStrategy":"type-guard","validationCode":"INT_FIELDS = {'window','period','fast_period','slow_period','signal_period','k_period','d_period'}\nfor k, v in params.items():\n    if k in INT_FIELDS:\n        try:\n            int(v)\n        except (TypeError, ValueError):\n            raise ValueError(f'{k} must be an integer, got {v!r}')","typeGuard":"def is_int_like(v) -> bool:\n    if v is None or v == '':\n        return True  # takes default\n    try:\n        int(v); return True\n    except (TypeError, ValueError):\n        return False","tryCatchPattern":"try:\n    normalize_indicator_parameters(alert_type, params)\nexcept ValueError as e:\n    if str(e).startswith('invalid ') or 'must be' in str(e):\n        return bad_request(str(e))\n    raise","preventionTips":["Use number inputs, not free text, for period-like fields.","Omit a field or send '' to take its default rather than sending junk.","Validate payloads with a schema (Pydantic/JSON Schema) before they reach the service."],"tags":["validation","type-error","alerts","parameters"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}