mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-05 08:10:14 +00:00
fix: handle RangeError in isbinaryfile library
- Add try-catch blocks around all isBinaryFile calls - Treat files as binary when isbinaryfile throws RangeError - Prevents extension from freezing when processing certain files - Fixes #6242
This commit is contained in:
parent
62160758fc
commit
17b08730dc
3 changed files with 27 additions and 3 deletions
|
|
@ -268,7 +268,14 @@ async function getFileOrFolderContent(
|
|||
fileContentPromises.push(
|
||||
(async () => {
|
||||
try {
|
||||
const isBinary = await isBinaryFile(absoluteFilePath).catch(() => false)
|
||||
let isBinary = false
|
||||
try {
|
||||
isBinary = await isBinaryFile(absoluteFilePath)
|
||||
} catch (error) {
|
||||
// If isBinaryFile throws an error (e.g., RangeError), treat as binary
|
||||
console.warn(`Error checking if file is binary for ${absoluteFilePath}:`, error)
|
||||
isBinary = true
|
||||
}
|
||||
if (isBinary) {
|
||||
return undefined
|
||||
}
|
||||
|
|
|
|||
|
|
@ -433,7 +433,17 @@ export async function readFileTool(
|
|||
|
||||
// Process approved files
|
||||
try {
|
||||
const [totalLines, isBinary] = await Promise.all([countFileLines(fullPath), isBinaryFile(fullPath)])
|
||||
let totalLines: number
|
||||
let isBinary: boolean
|
||||
|
||||
try {
|
||||
;[totalLines, isBinary] = await Promise.all([countFileLines(fullPath), isBinaryFile(fullPath)])
|
||||
} catch (error) {
|
||||
// If isBinaryFile throws an error (e.g., RangeError), treat the file as binary
|
||||
console.warn(`Error checking if file is binary for ${relPath}:`, error)
|
||||
totalLines = await countFileLines(fullPath)
|
||||
isBinary = true
|
||||
}
|
||||
|
||||
// Handle binary files (but allow specific file types that extractTextFromFile can handle)
|
||||
if (isBinary) {
|
||||
|
|
|
|||
|
|
@ -86,7 +86,14 @@ export async function extractTextFromFile(filePath: string, maxReadFileLine?: nu
|
|||
}
|
||||
|
||||
// Handle other files
|
||||
const isBinary = await isBinaryFile(filePath).catch(() => false)
|
||||
let isBinary = false
|
||||
try {
|
||||
isBinary = await isBinaryFile(filePath)
|
||||
} catch (error) {
|
||||
// If isBinaryFile throws an error (e.g., RangeError), treat as binary
|
||||
console.warn(`Error checking if file is binary for ${filePath}:`, error)
|
||||
isBinary = true
|
||||
}
|
||||
|
||||
if (!isBinary) {
|
||||
// Check if we need to apply line limit
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue