{"record":{"id":"872fe3ab2483bdfb","repo":"sgl-project/sglang","slug":"key-expected-field-type-got-value-r","errorCode":null,"errorMessage":"{key}: expected {field_type}, got {value!r}","messagePattern":"(.+?): expected (.+?), got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/debug_utils/dumper.py","lineNumber":123,"sourceCode":"\n        missing = object()\n        defaults = {f.name: f.default for f in fields(cls)}\n        result: dict = {}\n\n        for pair in pairs:\n            key, sep, value = pair.partition(\"=\")\n            if not sep:\n                raise ValueError(f\"Invalid config pair (missing '='): {pair!r}\")\n            default = defaults.get(key, missing)\n            if default is missing:\n                raise ValueError(\n                    f\"Unknown config key {key!r}. Valid keys: {sorted(defaults)}\"\n                )\n            try:\n                result[key] = cls._parse_env_value(value, default)\n            except (ValueError, TypeError) as exc:\n                field_type = type(default).__name__\n                raise TypeError(f\"{key}: expected {field_type}, got {value!r}\") from exc\n\n        return result\n\n\n_DEFAULT_EXP_NAME_PREFIX = \"dump_\"\n\n\n@dataclass(frozen=True)\nclass DumperConfig(_BaseConfig):\n    enable: bool = False\n    filter: Optional[str] = None\n    dir: str = \"/tmp/dumper\"\n    enable_output_file: bool = True\n    enable_output_console: bool = True\n    enable_value: bool = True\n    enable_grad: bool = False\n    enable_model_value: bool = False\n    enable_model_grad: bool = False","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/debug_utils/dumper.py#L105-L141","documentation":"Raised when _parse_env_value fails to coerce the string value to the type of the field's default (e.g. int('abc')). The original ValueError/TypeError is chained, and the message names the expected type (derived from type(default).__name__) and the offending raw value.","triggerScenarios":"Passing 'interval=abc' when the field default is an int; 'enabled=maybe' when the default is a bool; any string that the default type cannot parse.","commonSituations":"Booleans given as 'yes'/'1'? (parser may only accept 'true'/'false'), floats given with trailing units ('10ms'), locale-dependent numbers.","solutions":["Match the literal format the type expects: ints as digits, bools as true/false (check _parse_env_value's accepted bool spellings)","Strip units/quotes from the value string","Verify the field's default type via the 'Valid keys' error or dataclasses.fields before writing the value"],"exampleFix":"// before\ncfg = DumpConfig.from_kv_pairs([\"interval=abc\"])\n// after\ncfg = DumpConfig.from_kv_pairs([\"interval=10\"])","handlingStrategy":"try-catch","validationCode":"# pre-validate against default types\nfrom dataclasses import fields\nfor p in pairs:\n    k, _, v = p.partition(\"=\")\n    f = next(f for f in fields(DumpConfig) if f.name == k)\n    type(f.default)(v)  # raises early if unparseable","typeGuard":null,"tryCatchPattern":"try:\n    cfg = DumpConfig.from_kv_pairs(pairs)\nexcept TypeError as e:\n    # e.message names key, expected type, and bad value — fix that pair\n    ...","preventionTips":["Write booleans as true/false and numbers without units or quotes","Unit-test config strings near the code that defines them"],"tags":["config","type-coercion","validation"],"backgroundTag":"type-conversion-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}