Skip to content

Commit 7718bef

Browse files
committed
fix: separate countFileLines and isBinaryFile calls for accurate error handling
- Split Promise.all() into sequential calls to isolate error sources - countFileLines is called first and should not fail for valid files - Only isBinaryFile errors are caught and handled by treating file as binary - This ensures RangeError from isBinaryFile doesn't incorrectly attribute to countFileLines - Fixes issue where binary file detection errors were masking actual file reading problems
1 parent 6796e1a commit 7718bef

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/core/tools/readFileTool.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,14 +436,15 @@ export async function readFileTool(
436436
let totalLines: number
437437
let isBinary: boolean
438438

439+
// First, count the file lines (this should not fail for valid files)
440+
totalLines = await countFileLines(fullPath)
441+
442+
// Then check if it's binary, with error handling specific to isBinaryFile
439443
try {
440-
const results = await Promise.all([countFileLines(fullPath), isBinaryFile(fullPath)])
441-
totalLines = results[0]
442-
isBinary = results[1]
444+
isBinary = await isBinaryFile(fullPath)
443445
} catch (error) {
444446
// If isBinaryFile throws an error (e.g., RangeError), treat the file as binary
445447
console.warn(`Error checking if file is binary for ${relPath}:`, error)
446-
totalLines = await countFileLines(fullPath)
447448
isBinary = true
448449
}
449450

0 commit comments

Comments
 (0)