chenhg5/cc-connect · error
invalid line
Error message
invalid line
What it means
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.
Source
Thrown at core/reference_show.go:248
}
if lineNo > end {
break
}
if len(lines) >= maxLines {
truncated = true
break
}
lines = append(lines, scanner.Text())
}
if err := scanner.Err(); err != nil {
return nil, false, err
}
return lines, truncated, nil
}
func readFileContext(path string, line, before, after, maxLines int) ([]string, bool, error) {
if line <= 0 {
return nil, false, fmt.Errorf("invalid line")
}
start := line - before
if start < 1 {
start = 1
}
end := line + after
return readFileRange(path, start, end, maxLines)
}
func readDirEntries(path string, maxEntries int) ([]string, bool, error) {
if maxEntries <= 0 {
maxEntries = defaultShowMaxEntries
}
entries, err := os.ReadDir(path)
if err != nil {
return nil, false, err
}
out := make([]string, 0, minInt(len(entries), maxEntries))View on GitHub (pinned to 4000b2338a)
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
Example fix
// before /show file.go:0 // after /show file.go:1
Defensive patterns
Strategy: validation
Validate before calling
if line < 1 {
return fmt.Errorf("lines are 1-based; got %d", line)
} Try / catch
lines, _, err := readFileContext(path, line, before, after, max)
if err != nil && strings.Contains(err.Error(), "invalid line") {
return "line numbers start at 1", nil
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- invalid start line
- antigravity: invalid permission behavior %q
- auth.json missing tokens.access_token
- auth.json missing tokens.account_id
- tmux: 'session' option is required (name of the tmux session
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/b67da0e72f19f01f.
Report an issue: GitHub.