{"record":{"id":"17f5ec2eea9bce9a","repo":"alibaba/open-code-review","slug":"invalid-line-range-start-line-d-is-greater-than","errorCode":null,"errorMessage":"invalid line range: start_line %d is greater than end_line %d","messagePattern":"invalid line range: start_line (.+?) is greater than end_line (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tool/file_read.go","lineNumber":42,"sourceCode":"\tfilePath, _ := args[\"file_path\"].(string)\n\tif filePath == \"\" {\n\t\treturn \"Error: file_path is required\", nil\n\t}\n\n\tstartLine, hasStart := args[\"start_line\"].(float64)\n\tendLine, hasEnd := args[\"end_line\"].(float64)\n\tif !hasStart || startLine <= 0 {\n\t\tstartLine = 1\n\t}\n\tif !hasEnd || endLine <= 0 {\n\t\tendLine = 0\n\t}\n\n\tmaxLines := fileReadMaxLines\n\tif endLine > 0 {\n\t\trequested := int(endLine) - int(startLine) + 1\n\t\tif requested <= 0 {\n\t\t\treturn \"\", fmt.Errorf(\"invalid line range: start_line %d is greater than end_line %d\", int(startLine), int(endLine))\n\t\t}\n\t\tif requested < maxLines {\n\t\t\tmaxLines = requested\n\t\t}\n\t}\n\n\tlines, totalLines, err := p.FileReader.ReadLines(ctx, filePath, int(startLine), maxLines)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"file %q not found: %w\", filePath, err)\n\t}\n\n\tif totalLines > 0 && int(startLine)-1 >= totalLines {\n\t\treturn \"\", fmt.Errorf(\"file %q has only %d lines, requested range %d-%d\", filePath, totalLines, int(startLine), int(endLine))\n\t}\n\n\teffectiveEnd := totalLines\n\tif endLine > 0 && int(endLine) < effectiveEnd {\n\t\teffectiveEnd = int(endLine)","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/tool/file_read.go#L24-L60","documentation":"Validation error from FileReadProvider.Execute: when both start_line and end_line are provided (> 0), the requested range (end - start + 1) must be positive. If start_line > end_line the range is meaningless, so the tool refuses to read and returns this error instead of silently swapping or clamping the values.","triggerScenarios":"Calling the file_read tool with args like {\"start_line\": 50, \"end_line\": 10} — any start_line strictly greater than end_line, where both are present and positive.","commonSituations":"An LLM agent computing line numbers from stale file metadata (file shrank between listing and reading); off-by-one when converting 0-based to 1-based indices; reversed slice arguments passed through from upstream tooling.","solutions":["Swap the values so start_line <= end_line, or read the whole file by omitting end_line.","Re-fetch the file's current total line count and recompute the range.","If you only need lines from start onward, pass start_line alone; end_line is optional."],"exampleFix":"// before\n{\"file_path\": \"a.go\", \"start_line\": 50, \"end_line\": 10}\n// after\n{\"file_path\": \"a.go\", \"start_line\": 10, \"end_line\": 50}","handlingStrategy":"validation","validationCode":"start, end := int(args[\"start_line\"].(float64)), int(args[\"end_line\"].(float64))\nif end > 0 && start > end {\n    return fmt.Errorf(\"swap range: start_line %d > end_line %d\", start, end)\n}","typeGuard":"func validLineRange(start, end float64) bool { return start > 0 && (end <= 0 || start <= end) }","tryCatchPattern":"out, err := provider.Execute(ctx, args)\nif err != nil && strings.Contains(err.Error(), \"invalid line range\") {\n    args[\"start_line\"], args[\"end_line\"] = args[\"end_line\"], args[\"start_line\"]\n    out, err = provider.Execute(ctx, args)\n}","preventionTips":["Remember line numbers are 1-based; convert 0-based indices before calling.","Recompute ranges from freshly read file metadata, not stale results.","Omit end_line when you only need a starting offset."],"tags":["file-read","validation","arguments","tool-execution"],"backgroundTag":"invalid-parameter-range","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}