{"record":{"id":"8f57705825367d92","repo":"OpenBMB/ChatDev","slug":"end-line-must-be-an-integer","errorCode":null,"errorMessage":"end_line must be an integer","messagePattern":"end_line must be an integer","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"functions/function_calling/file.py","lineNumber":916,"sourceCode":"    return rendered\n\n\ndef _normalize_edits(edits: Sequence[Mapping[str, Any]]) -> List[TextEdit]:\n    if not edits:\n        raise ValueError(\"at least one edit instruction is required\")\n    normalized: List[TextEdit] = []\n    for item in edits:\n        if not isinstance(item, Mapping):\n            raise ValueError(\"each edit entry must be a mapping object\")\n        try:\n            start_line = int(item[\"start_line\"])\n        except (KeyError, TypeError, ValueError) as exc:\n            raise ValueError(\"start_line is required for each edit\") from exc\n        end_line_raw = item.get(\"end_line\", start_line)\n        try:\n            end_line = int(end_line_raw)\n        except (TypeError, ValueError) as exc:\n            raise ValueError(\"end_line must be an integer\") from exc\n        if start_line < 1:\n            raise ValueError(\"start_line must be >= 1\")\n        if end_line < start_line - 1:\n            raise ValueError(\"end_line must be >= start_line - 1\")\n        replacement = item.get(\"replacement\", \"\")\n        if not isinstance(replacement, str):\n            raise ValueError(\"replacement must be a string\")\n        normalized.append(\n            TextEdit(\n                start_line=start_line,\n                end_line=end_line,\n                replacement_lines=replacement.splitlines(),\n            )\n        )\n\n    normalized.sort(key=lambda edit: (edit.start_line, edit.end_line))\n    _validate_edit_ranges(normalized)\n    return normalized","sourceCodeStart":898,"sourceCodeEnd":934,"githubUrl":"https://github.com/OpenBMB/ChatDev/blob/4fb2db0ea90375ce1059f44fe03ffbd191a7a169/functions/function_calling/file.py#L898-L934","documentation":"The optional end_line field, when present, must be coercible to an integer. _normalize_edits runs int(end_line_raw) and converts TypeError/ValueError into this error, e.g. None, a non-numeric string, or a nested object. Note that int() accepts numeric strings like \"12\", so only genuinely non-integer values fail.","triggerScenarios":"Passing end_line=None; end_line=\"5-7\" or \"abc\"; end_line as a dict/list from malformed JSON; float strings like \"1.5\" (int('1.5') raises ValueError).","commonSituations":"LLM tool args with stringly-typed line ranges; JSON payloads where end_line was serialized as a range string; schemas that declare end_line as any/nullable and callers pass null meaning 'to EOF' (not supported).","solutions":["Pass end_line as an integer or omit it (it defaults to start_line)","To extend to end of file, pass the actual last line number, not null or 'EOF'","Validate that end_line is an int or int-coercible string before calling"],"exampleFix":"# before\napply_text_edits(path=\"a.py\", edits=[{\"start_line\": 2, \"end_line\": None, \"replacement\": \"x\"}])\n# after\napply_text_edits(path=\"a.py\", edits=[{\"start_line\": 2, \"end_line\": 2, \"replacement\": \"x\"}])","handlingStrategy":"validation","validationCode":"for e in edits:\n    if \"end_line\" in e and e[\"end_line\"] is None:\n        del e[\"end_line\"]  # default to start_line\napply_text_edits(path=path, edits=edits)","typeGuard":"def end_lines_valid(edits) -> bool:\n    return all(\n        e.get(\"end_line\", e.get(\"start_line\")) is not None\n        and str(e.get(\"end_line\", 0)).lstrip(\"-\").replace(\".\", \"\", 1).isdigit()\n        for e in edits\n    )","tryCatchPattern":"try:\n    apply_text_edits(path=path, edits=edits)\nexcept ValueError as e:\n    if \"end_line must be an integer\" in str(e):\n        for ed in edits:\n            if \"end_line\" in ed: ed[\"end_line\"] = int(ed[\"end_line\"])\n        apply_text_edits(path=path, edits=edits)\n    else:\n        raise","preventionTips":["Omit end_line rather than passing null","Coerce numeric strings to int at payload-build time","For 'to EOF', pass the file's actual last line number"],"tags":["validation","text-edit","type-mismatch"],"backgroundTag":"invalid-argument-type","analyzedSha":"4fb2db0ea90375ce1059f44fe03ffbd191a7a169","analyzedAt":"2026-08-27T14:35:29.622Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}