{"record":{"id":"380dee3c80748ad0","repo":"chenhg5/cc-connect","slug":"invalid-end-line","errorCode":null,"errorMessage":"invalid end line","messagePattern":"invalid end line","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/reference_show.go","lineNumber":207,"sourceCode":"\tfor scanner.Scan() {\n\t\tif len(lines) >= maxLines {\n\t\t\ttruncated = true\n\t\t\tbreak\n\t\t}\n\t\tlines = append(lines, scanner.Text())\n\t}\n\tif err := scanner.Err(); err != nil {\n\t\treturn nil, false, err\n\t}\n\treturn lines, truncated, nil\n}\n\nfunc readFileRange(path string, start, end, maxLines int) ([]string, bool, error) {\n\tif start <= 0 {\n\t\treturn nil, false, fmt.Errorf(\"invalid start line\")\n\t}\n\tif end <= 0 || end < start {\n\t\treturn nil, false, fmt.Errorf(\"invalid end line\")\n\t}\n\tif maxLines <= 0 {\n\t\tmaxLines = defaultShowMaxRange\n\t}\n\n\tf, err := os.Open(path)\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n\tdefer f.Close()\n\n\tscanner := bufio.NewScanner(f)\n\tbuf := make([]byte, 0, 64*1024)\n\tscanner.Buffer(buf, 1024*1024)\n\n\tlines := make([]string, 0, minInt(end-start+1, maxLines))\n\tlineNo := 0\n\ttruncated := false","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/reference_show.go#L189-L225","documentation":"readFileRange requires end to be a positive line number and at least equal to start, since ranges are inclusive 1-based [start,end]. An end of 0, negative, or below start is logically impossible and rejected.","triggerScenarios":"A reference location like file.go:10-5 (end < start) or file.go:10-0 (end <= 0); callers passing swapped or uninitialized end values.","commonSituations":"Users typing reversed ranges (10-5 instead of 5-10); parsers misordering the two halves of an N-M suffix; default-zero end variables never set.","solutions":["Swap the range bounds so end >= start before calling (or normalize inside the parser)","Ensure the end line defaults to start (or file length) when only one line is given","Validate user-supplied N-M locations at parse time and reject end < start with a clear message"],"exampleFix":"// before\nreadFileRange(path, 10, 5, 100) // end < start\n// after\nif end < start {\n    start, end = end, start\n}\nreadFileRange(path, start, end, 100)","handlingStrategy":"validation","validationCode":"if end < 1 || end < start {\n    return fmt.Errorf(\"invalid range %d-%d\", start, end)\n}","typeGuard":null,"tryCatchPattern":"lines, _, err := readFileRange(path, start, end, max)\nif err != nil && strings.Contains(err.Error(), \"invalid end line\") {\n    return \"use format :start-end with end >= start\", nil\n}","preventionTips":["Normalize ranges (swap if reversed) in the location parser","Default end to start or EOF when omitted","Document the N-M syntax order in help text"],"tags":["go","validation","range"],"backgroundTag":"value-out-of-range","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}