Skip to content

Commit b41dd73

Browse files
mrubensEric Wheeler
andauthored
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 <[email protected]> Co-authored-by: Eric Wheeler <[email protected]>
1 parent 2597347 commit b41dd73

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/core/Cline.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,11 +2341,11 @@ export class Cline extends EventEmitter<ClineEvents> {
23412341
isFileTruncated = true
23422342

23432343
const res = await Promise.all([
2344-
readLines(absolutePath, maxReadFileLine - 1, 0),
2344+
maxReadFileLine > 0 ? readLines(absolutePath, maxReadFileLine - 1, 0) : "",
23452345
parseSourceCodeDefinitionsForFile(absolutePath, this.rooIgnoreController),
23462346
])
23472347

2348-
content = addLineNumbers(res[0])
2348+
content = res[0].length > 0 ? addLineNumbers(res[0]) : ""
23492349
const result = res[1]
23502350
if (result) {
23512351
sourceCodeDef = `\n\n${result}`

0 commit comments

Comments
 (0)