Skip to content

Bug: writeToFileTool silently fails on missing or empty path/content parametersΒ #4113

@Ruakij

Description

@Ruakij

App Version

v3.19.0

API Provider

Not Applicable / Other

Model Used

N/A

πŸ” Steps to Reproduce

    • write_to_file tool with missing or empty path parameter is invoked
    • write_to_file tool with missing content parameter is invoked
  1. In both cases, the function in writeToFileTool.ts silently returns on line 29 without any error handling leading to no action or error happening.

Images

Image
Image

πŸ’₯ Outcome Summary

The issue occurs because the early validation check silently returns, for both partial and non-partial blocks, instead of properly handling the error case.

if (!relPath || newContent === undefined) {
  // checking for newContent ensure relPath is complete
  // wait so we can determine if it's a new file or editing an existing file
  return
}

This was discovered during PR #3871 via Unit-Tests for writeToFileTool.test.ts:

// ..
	describe("parameter validation", () => {
		it("errors and resets on missing path parameter", async () => {
			await executeWriteFileTool({ path: undefined })

			expect(mockCline.consecutiveMistakeCount).toBe(1)
			expect(mockCline.recordToolError).toHaveBeenCalledWith("write_to_file")
			expect(mockCline.sayAndCreateMissingParamError).toHaveBeenCalledWith("write_to_file", "path")
			expect(mockCline.diffViewProvider.reset).toHaveBeenCalled()
		})

		it("errors and resets on empty path parameter", async () => {
			await executeWriteFileTool({ path: "" })

			expect(mockCline.consecutiveMistakeCount).toBe(1)
			expect(mockCline.recordToolError).toHaveBeenCalledWith("write_to_file")
			expect(mockCline.sayAndCreateMissingParamError).toHaveBeenCalledWith("write_to_file", "path")
			expect(mockCline.diffViewProvider.reset).toHaveBeenCalled()
		})

		it("errors and resets on missing content parameter", async () => {
			await executeWriteFileTool({ content: undefined })

			expect(mockCline.consecutiveMistakeCount).toBe(1)
			expect(mockCline.recordToolError).toHaveBeenCalledWith("write_to_file")
			expect(mockCline.sayAndCreateMissingParamError).toHaveBeenCalledWith("write_to_file", "content")
			expect(mockCline.diffViewProvider.reset).toHaveBeenCalled()
		})
	})
// ..

πŸ“„ Relevant Logs or Errors (Optional)

Metadata

Metadata

Assignees

Labels

Issue - In ProgressSomeone is actively working on this. Should link to a PR soon.bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions