{"record":{"id":"7cb59b984d13e194","repo":"chenhg5/cc-connect","slug":"invalid-start-line","errorCode":null,"errorMessage":"invalid start line","messagePattern":"invalid start line","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/reference_show.go","lineNumber":204,"sourceCode":"\n\tlines := make([]string, 0, maxLines)\n\ttruncated := false\n\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","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/reference_show.go#L186-L222","documentation":"readFileRange validates its bounds before opening the file; start must be a positive 1-based line number. start <= 0 means the requested range begins before the first line, which is invalid for 1-based file line addressing.","triggerScenarios":"renderReferenceFile or readFileContext computing/carrying a start line of 0 or negative — e.g. a reference like file.go:0 or a context window calculation that underflows before clamping.","commonSituations":"Users specifying line 0 in a :N-M location; code that computes start = line - before without flooring at 1 before this call; off-by-one in reference parsers converting 0-based user input.","solutions":["Clamp the start line to a minimum of 1 before calling readFileRange","Reject location formats with start < 1 at reference-parse time and tell the user lines are 1-based","Fix the caller's start computation to floor at 1 (as readFileContext already does)"],"exampleFix":"// before\nreadFileRange(path, 0, 20, 100)\n// after\nif start < 1 {\n    start = 1\n}\nreadFileRange(path, start, 20, 100)","handlingStrategy":"validation","validationCode":"if start < 1 {\n    return fmt.Errorf(\"lines are 1-based; got %d\", start)\n}","typeGuard":null,"tryCatchPattern":"lines, truncated, err := readFileRange(path, start, end, max)\nif err != nil && strings.Contains(err.Error(), \"invalid start line\") {\n    start = 1\n    lines, truncated, err = readFileRange(path, start, end, max)\n}","preventionTips":["Floor computed start values at 1 before calling","Reject :0 or negative line locations in the parser","Convert user 0-based input to 1-based explicitly at the boundary"],"tags":["go","validation","line-numbers"],"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-14T00:17:10.932Z"}