fix: prevent negative line index when maxReadFileLine is zero (#1915)

When maxReadFileLine setting was set to zero, the code would attempt to read lines with a negative end index
(maxReadFileLine - 1 = -1), causing the readLines function to reject the request.

This change:
- Checks if maxReadFileLine is greater than zero before calling readLines
- Returns an empty string when maxReadFileLine is zero
- Ensures content is only formatted with line numbers when it's not empty

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
Co-authored-by: Eric Wheeler <roo-code@z.ewheeler.org>
This commit is contained in:
Matt Rubens 2025-03-23 02:09:48 -04:00 committed by GitHub
parent 2597347e91
commit b41dd739f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2341,11 +2341,11 @@ export class Cline extends EventEmitter<ClineEvents> {
isFileTruncated = true
const res = await Promise.all([
readLines(absolutePath, maxReadFileLine - 1, 0),
maxReadFileLine > 0 ? readLines(absolutePath, maxReadFileLine - 1, 0) : "",
parseSourceCodeDefinitionsForFile(absolutePath, this.rooIgnoreController),
])
content = addLineNumbers(res[0])
content = res[0].length > 0 ? addLineNumbers(res[0]) : ""
const result = res[1]
if (result) {
sourceCodeDef = `\n\n${result}`