{"record":{"id":"ee83b0c3988d29d5","repo":"datawhalechina/hello-agents","slug":"name-ee83b0","errorCode":null,"errorMessage":"{name} 必须是数字","messagePattern":"\\{name\\} 必须是数字","errorType":"exception","errorClass":"ConfigurationError","httpStatus":null,"severity":"error","filePath":"Co-creation-projects/zenith191-RequirementClarifierAgent/src/config.py","lineNumber":20,"sourceCode":"\nfrom __future__ import annotations\n\nimport os\nfrom dataclasses import dataclass\n\n\nclass ConfigurationError(ValueError):\n    \"\"\"配置缺失或配置值无效。\"\"\"\n\n\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","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/zenith191-RequirementClarifierAgent/src/config.py#L2-L38","documentation":"Raised by the _read_float helper in src/config.py when an environment variable expected to hold a float (e.g. LLM_TEMPERATURE) is set to a non-numeric value. float(raw_value) raises ValueError, which is chained into ConfigurationError. It fires only when the variable is set and non-empty — unset variables fall back to the default.","triggerScenarios":"Setting LLM_TEMPERATURE=high, LLM_TEMPERATURE=0,7 (comma decimal), or any string with stray characters/quotes in .env or the shell environment, then loading configuration (from_env or equivalent).","commonSituations":"Copy-pasting config from a tutorial that uses words instead of numbers; locale confusion (comma vs dot decimal); stray quotes in .env like TEMPERATURE=\"0.3\"\"; CI injecting a wrong secret value into the wrong variable name.","solutions":["Check the exact value: print the env var or inspect .env for the float-typed settings (LLM_TEMPERATURE).","Fix the value to a plain decimal like 0.2 (dot separator, no quotes or units).","Unset the variable if you want the documented default instead of overriding it."],"exampleFix":"# .env before\nLLM_TEMPERATURE=high\n\n# .env after\nLLM_TEMPERATURE=0.2","handlingStrategy":"validation","validationCode":"import os\n\ndef read_float(name: str, default: float) -> float:\n    raw = os.getenv(name)\n    if raw is None or not raw.strip():\n        return default\n    try:\n        return float(raw)\n    except ValueError as e:\n        raise ValueError(f\"{name}={raw!r} is not a valid float\") from e\n\n# fail loudly at startup, not mid-request:\nLLM_TEMPERATURE = read_float(\"LLM_TEMPERATURE\", 0.2)","typeGuard":null,"tryCatchPattern":"try:\n    settings = load_settings()\nexcept ConfigurationError as e:\n    print(f\"Bad config: {e}\")\n    sys.exit(2)  # config errors should stop startup, not be retried","preventionTips":["Validate all env config once at process start and exit fast on error.","Use a linter/schema (pydantic-settings, dotenv-linter) for .env files.","In docker-compose/K8s, define env values with explicit types and unit-test startup with a minimal env."],"tags":["python","configuration","environment-variables","validation"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}