From 01cfde70779c32a46bef14aa15eeaeb84b812430 Mon Sep 17 00:00:00 2001 From: Brace Sproul Date: Thu, 29 May 2025 17:12:32 -0700 Subject: [PATCH] fix: Include apply patch err message in tool result (#54) --- apps/open-swe/src/tools/apply-patch.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/open-swe/src/tools/apply-patch.ts b/apps/open-swe/src/tools/apply-patch.ts index ac265c14..dde967ca 100644 --- a/apps/open-swe/src/tools/apply-patch.ts +++ b/apps/open-swe/src/tools/apply-patch.ts @@ -57,10 +57,12 @@ export const applyPatchTool = tool( let patchedContent: string | false; let fixedDiff: string | false = false; + let errorApplyingPatchMessage: string | undefined; try { logger.info(`Applying patch to file ${file_path}`); patchedContent = applyPatch(readFileOutput, diff); } catch (e) { + errorApplyingPatchMessage = e instanceof Error ? e.message : undefined; try { logger.warn("Failed to apply patch, trying to fix diff", { error: e, @@ -116,7 +118,10 @@ export const applyPatchTool = tool( let resultMessage = `Successfully applied diff to \`${file_path}\` and saved changes.`; logger.info(resultMessage); if (fixedDiff) { - resultMessage += `\n\nNOTE: The generated diff was NOT formatted properly, and had to be fixed. The diff which was applied is:\n\n${fixedDiff}\n`; + resultMessage += + "\n\nNOTE: The generated diff was NOT formatted properly, and had to be fixed." + + `\nHere is the error that was thrown when your generated diff was applied:\n\n${errorApplyingPatchMessage}\n` + + `\nThe diff which was applied is:\n\n${fixedDiff}\n`; } return { result: resultMessage,