Skip to content

Commit

Permalink
Improve failed diff edit response
Browse files Browse the repository at this point in the history
  • Loading branch information
saoudrizwan committed Dec 26, 2024
1 parent 2c0340e commit b2cae6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/core/Cline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/core/assistant-message/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
)
}
}
Expand Down

0 comments on commit b2cae6c

Please sign in to comment.