Improve failed diff edit response

This commit is contained in:
Saoud Rizwan 2024-12-26 12:55:00 -08:00
parent 2c0340eaaa
commit b2cae6c2fb
2 changed files with 8 additions and 2 deletions

View file

@ -1140,7 +1140,13 @@ export class Cline {
} catch (error) {
await this.say("diff_error", relPath)
pushToolResult(
formatResponse.toolError(`Error writing file: ${(error as Error)?.message}`),
formatResponse.toolError(
`${(error as Error)?.message}\n\n` +
`This is likely due to character mismatches between the SEARCH block and the actual file.\n\n` +
`The file was reverted to its original state:\n\n` +
`<file_content path="${relPath.toPosix()}">\n${this.diffViewProvider.originalContent}\n</file_content>\n\n` +
`Try again with a more precise SEARCH block.\n(If you keep running into this error, you may use the write_to_file tool as a workaround.)`,
),
)
await this.diffViewProvider.revertChanges()
await this.diffViewProvider.reset()

View file

@ -297,7 +297,7 @@ export async function constructNewFileContent(
;[searchMatchIndex, searchEndIndex] = blockMatch
} else {
throw new Error(
`The SEARCH block:\n${currentSearchContent.trimEnd()}\n...does not match anything in the file.\nThis is likely due to differences in whitespace or line endings between the SEARCH block and the actual file. Try again with a more precise SEARCH block.\n(If you keep running into this error, you may use the write_to_file tool as a workaround.)`,
`The SEARCH block:\n${currentSearchContent.trimEnd()}\n...does not match anything in the file.`,
)
}
}