diff --git a/src/core/tools/ReadFileTool.ts b/src/core/tools/ReadFileTool.ts index 11c1e077997..363e6065073 100644 --- a/src/core/tools/ReadFileTool.ts +++ b/src/core/tools/ReadFileTool.ts @@ -147,7 +147,7 @@ export class ReadFileTool extends BaseTool<"read_file"> { error: errorMsg, xmlContent: `${relPath}Error reading file: ${errorMsg}`, }) - await handleError(`reading file ${relPath}`, new Error(errorMsg)) + await task.say("error", `Error reading file ${relPath}: ${errorMsg}`) hasRangeError = true break } @@ -158,7 +158,7 @@ export class ReadFileTool extends BaseTool<"read_file"> { error: errorMsg, xmlContent: `${relPath}Error reading file: ${errorMsg}`, }) - await handleError(`reading file ${relPath}`, new Error(errorMsg)) + await task.say("error", `Error reading file ${relPath}: ${errorMsg}`) hasRangeError = true break } @@ -363,10 +363,7 @@ export class ReadFileTool extends BaseTool<"read_file"> { error: `Error reading image file: ${errorMsg}`, xmlContent: `${relPath}Error reading image file: ${errorMsg}`, }) - await handleError( - `reading image file ${relPath}`, - error instanceof Error ? error : new Error(errorMsg), - ) + await task.say("error", `Error reading image file ${relPath}: ${errorMsg}`) continue } } @@ -498,7 +495,7 @@ export class ReadFileTool extends BaseTool<"read_file"> { error: `Error reading file: ${errorMsg}`, xmlContent: `${relPath}Error reading file: ${errorMsg}`, }) - await handleError(`reading file ${relPath}`, error instanceof Error ? error : new Error(errorMsg)) + await task.say("error", `Error reading file ${relPath}: ${errorMsg}`) } } @@ -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) diff --git a/src/core/tools/__tests__/readFileTool.spec.ts b/src/core/tools/__tests__/readFileTool.spec.ts index bff1f6c58f4..a81906718b9 100644 --- a/src/core/tools/__tests__/readFileTool.spec.ts +++ b/src/core/tools/__tests__/readFileTool.spec.ts @@ -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 = `${testImagePath}` const toolUse: ReadFileToolUse = { type: "tool_use", @@ -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 }, @@ -1625,7 +1622,8 @@ describe("read_file tool with image support", () => { // Verify error handling expect(toolResult).toContain("Error reading image file: Failed to read image") - expect(handleErrorSpy).toHaveBeenCalled() + // Verify that say was called to show error to user + expect(localMockCline.say).toHaveBeenCalledWith("error", expect.stringContaining("Failed to read image")) }) })