From b41dd739f3d4b49ce243ee307951d0d20590a524 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Sun, 23 Mar 2025 02:09:48 -0400 Subject: [PATCH] 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 Co-authored-by: Eric Wheeler --- src/core/Cline.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 20af9ee565..262c2233b4 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -2341,11 +2341,11 @@ export class Cline extends EventEmitter { 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}`