fix: ensure write_to_file returns error response to LLM on failure

- Add pushToolResult() call in error handler to return formatted error message
- Extract toolProtocol from callbacks for error formatting
- Update test to verify pushToolResult is called with error message
- Fixes ROO-320: UI buttons getting stuck after file write errors
This commit is contained in:
Roo Code 2026-01-18 05:08:53 +00:00
parent 802b40a790
commit 0a59d92964
2 changed files with 4 additions and 2 deletions

View file

@ -34,7 +34,7 @@ export class WriteToFileTool extends BaseTool<"write_to_file"> {
}
async execute(params: WriteToFileParams, task: Task, callbacks: ToolCallbacks): Promise<void> {
const { pushToolResult, handleError, askApproval, removeClosingTag } = callbacks
const { pushToolResult, handleError, askApproval, removeClosingTag, toolProtocol } = callbacks
const relPath = params.path
let newContent = params.content
@ -194,6 +194,7 @@ export class WriteToFileTool extends BaseTool<"write_to_file"> {
return
} catch (error) {
await handleError("writing file", error as Error)
pushToolResult(formatResponse.toolError((error as Error).message, toolProtocol))
await task.diffViewProvider.reset()
this.resetPartialState()
return

View file

@ -443,12 +443,13 @@ describe("writeToFileTool", () => {
})
describe("error handling", () => {
it("handles general file operation errors", async () => {
it("handles general file operation errors and returns error to LLM", async () => {
mockCline.diffViewProvider.open.mockRejectedValue(new Error("General error"))
await executeWriteFileTool({})
expect(mockHandleError).toHaveBeenCalledWith("writing file", expect.any(Error))
expect(mockPushToolResult).toHaveBeenCalledWith("Error: General error")
expect(mockCline.diffViewProvider.reset).toHaveBeenCalled()
})