{"record":{"id":"75a7dc41ac16192b","repo":"datawhalechina/hello-agents","slug":"name-75a7dc","errorCode":null,"errorMessage":"{name} 必须是整数","messagePattern":"\\{name\\} 必须是整数","errorType":"exception","errorClass":"ConfigurationError","httpStatus":null,"severity":"error","filePath":"Co-creation-projects/zenith191-RequirementClarifierAgent/src/config.py","lineNumber":30,"sourceCode":"\ndef _read_float(name: str, default: float) -> float:\n    raw_value = os.getenv(name)\n    if raw_value is None or not raw_value.strip():\n        return default\n    try:\n        return float(raw_value)\n    except ValueError as exc:\n        raise ConfigurationError(f\"{name} 必须是数字\") from exc\n\n\ndef _read_int(name: str, default: int) -> int:\n    raw_value = os.getenv(name)\n    if raw_value is None or not raw_value.strip():\n        return default\n    try:\n        return int(raw_value)\n    except ValueError as exc:\n        raise ConfigurationError(f\"{name} 必须是整数\") from exc\n\n\n@dataclass(frozen=True)\nclass LLMSettings:\n    \"\"\"创建 HelloAgentsLLM 所需的显式配置。\"\"\"\n\n    model: str\n    api_key: str\n    base_url: str\n    temperature: float = 0.2\n    timeout: int = 120\n\n    @classmethod\n    def from_env(cls) -> \"LLMSettings\":\n        \"\"\"从 HelloAgents 官方环境变量读取配置并完成校验。\"\"\"\n\n        settings = cls(\n            model=os.getenv(\"LLM_MODEL_ID\", \"\").strip(),","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/zenith191-RequirementClarifierAgent/src/config.py#L12-L48","documentation":"Raised by _read_int in src/config.py when an integer-typed env var (e.g. LLM_TIMEOUT) fails int(raw_value). Note int('120.0') also fails — Python's int() rejects decimal strings, unlike float('120'). The original ValueError is chained via 'from exc', preserving the root cause.","triggerScenarios":"Setting LLM_TIMEOUT=120s, LLM_TIMEOUT=120.0, or LLM_TIMEOUT=-1 in .env, then constructing settings from the environment.","commonSituations":"Adding a unit suffix ('30s') copied from a docker-compose example; entering 120.5 because the field was assumed to accept floats; whitespace-embedded values from CI secrets.","solutions":["Set the variable to a bare integer string, e.g. LLM_TIMEOUT=120 (no decimals, no units).","If a fractional value was intended, round it to an integer first: LLM_TIMEOUT=120 not 120.0.","Verify with: python -c \"import os; print(repr(os.getenv('LLM_TIMEOUT')))\"."],"exampleFix":"# .env before\nLLM_TIMEOUT=120.0\n\n# .env after\nLLM_TIMEOUT=120","handlingStrategy":"validation","validationCode":"import os\n\ndef read_int(name: str, default: int) -> int:\n    raw = os.getenv(name)\n    if raw is None or not raw.strip():\n        return default\n    return int(float(raw))  # accept '120.0' gracefully, or:\n    # return int(raw)  # strict: rejects decimals — pick one policy and document it","typeGuard":null,"tryCatchPattern":"try:\n    settings = load_settings()\nexcept ConfigurationError as e:\n    if \"整数\" in str(e):\n        print(\"Integer env var malformed — check LLM_TIMEOUT\")\n    raise","preventionTips":["Document each env var's expected type in .env.example with example values.","Never attach units to numeric env vars; keep units in code.","Add a startup smoke test in CI that loads settings with the production env template."],"tags":["python","configuration","environment-variables","validation"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}