Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/core/mentions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this nested try-catch pattern intentional? While it works, it's inconsistent with the error handling approach used in the other two files. Consider using a single try-catch block like in extract-text.ts for consistency:

let isBinary = false
try {
    isBinary = await isBinaryFile(absoluteFilePath)
} catch (error) {
    console.warn(`Error checking if file is binary for ${absoluteFilePath}:`, error)
    isBinary = true
}

} 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
}
Expand Down
12 changes: 11 additions & 1 deletion src/core/tools/readFileTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion src/integrations/misc/extract-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down