{"record":{"id":"472e6be17065a7a1","repo":"plandex-ai/plandex","slug":"start-line-is-greater-than-end-line-d-d","errorCode":null,"errorMessage":"start line is greater than end line: %d > %d","messagePattern":"start line is greater than end line: (.+?) > (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/shared/streamed_change.go","lineNumber":66,"sourceCode":"\t\tif streamedChangeSection.EndLine > 0 {\n\t\t\tendLine = streamedChangeSection.EndLine\n\t\t} else {\n\t\t\tendLine = startLine\n\t\t}\n\t} else {\n\t\tendLine, err = ExtractLineNumberWithPrefix(streamedChangeSection.EndLineString, prefix)\n\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error extracting end line number: %v\\n\", err)\n\t\t\treturn 0, 0, fmt.Errorf(\"error extracting end line number: %v\", err)\n\t\t}\n\t}\n\n\tlog.Printf(\"StartLine: %d, EndLine: %d\\n\", startLine, endLine)\n\n\tif startLine > endLine {\n\t\tlog.Printf(\"Start line is greater than end line: %d > %d\\n\", startLine, endLine)\n\t\treturn 0, 0, fmt.Errorf(\"start line is greater than end line: %d > %d\", startLine, endLine)\n\t}\n\n\tif startLine < 1 {\n\t\tlog.Printf(\"Start line is less than 1: %d\\n\", startLine)\n\t\treturn 0, 0, fmt.Errorf(\"start line is less than 1: %d\", startLine)\n\t}\n\n\treturn startLine, endLine, nil\n}\n\nfunc ExtractLineNumber(line string) (int, error) {\n\treturn ExtractLineNumberWithPrefix(line, \"pdx-\")\n}\n\nfunc ExtractLineNumberWithPrefix(line, prefix string) (int, error) {\n\t// Split the line at the first space to isolate the line number\n\tparts := strings.SplitN(line, \" \", 2)\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/shared/streamed_change.go#L48-L84","documentation":"After successfully parsing both line numbers, GetLinesWithPrefix validates the range and rejects it when the start line exceeds the end line, since that is an empty/invalid selection. This catches swapped or mis-parsed line markers in the streamed change section.","triggerScenarios":"GetLines with a section whose parsed StartLine > EndLine — e.g. the LLM emitted the markers in reverse order, or prefix parsing picked the wrong numbers from adjacent lines.","commonSituations":"Model output confusion in long diffs; sections generated from files reordered after context capture; copy/paste of markers into the wrong order.","solutions":["Re-generate the streamed change section with correct ordering","If the intent was a whole-file or open-ended range, leave EndLineString empty instead of using a smaller end line","Validate parsed numbers before calling GetLines (see validationCode)","Check whether custom section parsing reversed StartLineString/EndLineString assignment"],"exampleFix":"// before\nsection.StartLineString, section.EndLineString = endStr, startStr\n// after\nsection.StartLineString, section.EndLineString = startStr, endStr","handlingStrategy":"validation","validationCode":"func orderedRange(section shared.StreamedChangeSection, prefix string) error {\n    s, errS := shared.ExtractLineNumberWithPrefix(section.StartLineString, prefix)\n    e, errE := shared.ExtractLineNumberWithPrefix(section.EndLineString, prefix)\n    if errS != nil || errE != nil { return fmt.Errorf(\"parse: %v %v\", errS, errE) }\n    if s > e { return fmt.Errorf(\"start %d > end %d\", s, e) }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"start, end, err := GetLinesWithPrefix(section, prefix)\nif err != nil {\n    if strings.Contains(err.Error(), \"greater than end line\") {\n        section.StartLineString, section.EndLineString = section.EndLineString, section.StartLineString // attempt swap\n        start, end, err = GetLinesWithPrefix(section, prefix)\n    }\n    if err != nil { return err }\n}","preventionTips":["Validate start <= end when constructing sections","Don't fabricate end markers; use empty EndLineString for open ranges","Check whether your parser swaps start/end fields"],"tags":["go","validation","line-numbers","streaming"],"backgroundTag":"invalid-line-range","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}