{"record":{"id":"b67da0e72f19f01f","repo":"chenhg5/cc-connect","slug":"invalid-line","errorCode":null,"errorMessage":"invalid line","messagePattern":"invalid line","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/reference_show.go","lineNumber":248,"sourceCode":"\t\t}\n\t\tif lineNo > end {\n\t\t\tbreak\n\t\t}\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 readFileContext(path string, line, before, after, maxLines int) ([]string, bool, error) {\n\tif line <= 0 {\n\t\treturn nil, false, fmt.Errorf(\"invalid line\")\n\t}\n\tstart := line - before\n\tif start < 1 {\n\t\tstart = 1\n\t}\n\tend := line + after\n\treturn readFileRange(path, start, end, maxLines)\n}\n\nfunc readDirEntries(path string, maxEntries int) ([]string, bool, error) {\n\tif maxEntries <= 0 {\n\t\tmaxEntries = defaultShowMaxEntries\n\t}\n\tentries, err := os.ReadDir(path)\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n\tout := make([]string, 0, minInt(len(entries), maxEntries))","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/reference_show.go#L230-L266","documentation":"readFileContext validates its line argument before computing the read window: a line number <= 0 was supplied (callers should pass 1-based line numbers). Sentinel validation error, not a file I/O failure.","triggerScenarios":"renderReferenceFile calling readFileContext with a line number of 0 or negative, typically from a reference location like file.go:0 or a parser that failed to extract the line.","commonSituations":"User writes file.go:0 expecting 0-based indexing; a regex capture in the parser yields an empty/invalid number converted to 0; tests passing zero-value ints.","solutions":["Use 1-based line numbers (file.go:1 for the first line)","Clamp or reject line < 1 in the location parser before building the reference request","Return a user-facing hint that lines are 1-based when parsing fails"],"exampleFix":"// before\n/show file.go:0\n// after\n/show file.go:1","handlingStrategy":"validation","validationCode":"if line < 1 {\n    return fmt.Errorf(\"lines are 1-based; got %d\", line)\n}","typeGuard":null,"tryCatchPattern":"lines, _, err := readFileContext(path, line, before, after, max)\nif err != nil && strings.Contains(err.Error(), \"invalid line\") {\n    return \"line numbers start at 1\", nil\n}","preventionTips":["Parse location numbers with strconv and reject <= 0 with a user hint","Clamp anchor line to 1 in the parser","Add tests for :0 and negative line inputs"],"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"}