Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 5 additions & 8 deletions src/core/tools/ReadFileTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class ReadFileTool extends BaseTool<"read_file"> {
error: errorMsg,
xmlContent: `<file><path>${relPath}</path><error>Error reading file: ${errorMsg}</error></file>`,
})
await handleError(`reading file ${relPath}`, new Error(errorMsg))
await task.say("error", `Error reading file ${relPath}: ${errorMsg}`)
hasRangeError = true
break
}
Expand All @@ -158,7 +158,7 @@ export class ReadFileTool extends BaseTool<"read_file"> {
error: errorMsg,
xmlContent: `<file><path>${relPath}</path><error>Error reading file: ${errorMsg}</error></file>`,
})
await handleError(`reading file ${relPath}`, new Error(errorMsg))
await task.say("error", `Error reading file ${relPath}: ${errorMsg}`)
hasRangeError = true
break
}
Expand Down Expand Up @@ -363,10 +363,7 @@ export class ReadFileTool extends BaseTool<"read_file"> {
error: `Error reading image file: ${errorMsg}`,
xmlContent: `<file><path>${relPath}</path><error>Error reading image file: ${errorMsg}</error></file>`,
})
await handleError(
`reading image file ${relPath}`,
error instanceof Error ? error : new Error(errorMsg),
)
await task.say("error", `Error reading image file ${relPath}: ${errorMsg}`)
continue
}
}
Expand Down Expand Up @@ -498,7 +495,7 @@ export class ReadFileTool extends BaseTool<"read_file"> {
error: `Error reading file: ${errorMsg}`,
xmlContent: `<file><path>${relPath}</path><error>Error reading file: ${errorMsg}</error></file>`,
})
await handleError(`reading file ${relPath}`, error instanceof Error ? error : new Error(errorMsg))
await task.say("error", `Error reading file ${relPath}: ${errorMsg}`)
}
}

Expand Down Expand Up @@ -570,7 +567,7 @@ export class ReadFileTool extends BaseTool<"read_file"> {
})
}

await handleError(`reading file ${relPath}`, error instanceof Error ? error : new Error(errorMsg))
await task.say("error", `Error reading file ${relPath}: ${errorMsg}`)

const xmlResults = fileResults.filter((result) => result.xmlContent).map((result) => result.xmlContent)

Expand Down
10 changes: 4 additions & 6 deletions src/core/tools/__tests__/readFileTool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1602,10 +1602,7 @@ describe("read_file tool with image support", () => {
// Setup - simulate read error
mockedFsReadFile.mockRejectedValue(new Error("Failed to read image"))

// Create a spy for handleError
const handleErrorSpy = vi.fn()

// Execute with the spy
// Execute
const argsContent = `<file><path>${testImagePath}</path></file>`
const toolUse: ReadFileToolUse = {
type: "tool_use",
Expand All @@ -1616,7 +1613,7 @@ describe("read_file tool with image support", () => {

await readFileTool.handle(localMockCline, toolUse, {
askApproval: localMockCline.ask,
handleError: handleErrorSpy, // Use our spy here
handleError: vi.fn(),
pushToolResult: (result: ToolResponse) => {
toolResult = result
},
Expand All @@ -1625,7 +1622,8 @@ describe("read_file tool with image support", () => {

// Verify error handling
expect(toolResult).toContain("<error>Error reading image file: Failed to read image</error>")
expect(handleErrorSpy).toHaveBeenCalled()
// Verify that say was called to show error to user
expect(localMockCline.say).toHaveBeenCalledWith("error", expect.stringContaining("Failed to read image"))
})
})

Expand Down
Loading