diff --git a/apps/open-swe/src/tools/apply-patch.ts b/apps/open-swe/src/tools/apply-patch.ts index 7f4c4acf..faf74201 100644 --- a/apps/open-swe/src/tools/apply-patch.ts +++ b/apps/open-swe/src/tools/apply-patch.ts @@ -50,10 +50,7 @@ export const applyPatchTool = tool( ); if (!readFileSuccess) { logger.error(readFileOutput); - return { - result: readFileOutput, - status: "error", - }; + throw new Error(readFileOutput); } let patchedContent: string | false; @@ -85,10 +82,9 @@ export const applyPatchTool = tool( : { error: e }), }); const errMessage = e instanceof Error ? e.message : "Unknown error"; - return { - result: `FAILED TO APPLY PATCH: The diff could not be applied to file '${file_path}'.\n\nError: ${errMessage}`, - status: "error", - }; + throw new Error( + `FAILED TO APPLY PATCH: The diff could not be applied to file '${file_path}'.\n\nError: ${errMessage}`, + ); } } @@ -96,10 +92,9 @@ export const applyPatchTool = tool( logger.error( `FAILED TO APPLY PATCH: The diff could not be applied to file '${file_path}'. This may be due to an invalid diff format or conflicting changes with the file's current content. Original content length: ${readFileOutput.length}, Diff: ${diff.substring(0, 100)}...`, ); - return { - result: `FAILED TO APPLY PATCH: The diff could not be applied to file '${file_path}'. This may be due to an invalid diff format or conflicting changes with the file's current content. Original content length: ${readFileOutput.length}, Diff: ${diff.substring(0, 100)}...`, - status: "error", - }; + throw new Error( + `FAILED TO APPLY PATCH: The diff could not be applied to file '${file_path}'. This may be due to an invalid diff format or conflicting changes with the file's current content. Original content length: ${readFileOutput.length}, Diff: ${diff.substring(0, 100)}...`, + ); } const { success: writeFileSuccess, output: writeFileOutput } = @@ -110,10 +105,7 @@ export const applyPatchTool = tool( logger.error("Failed to write file", { writeFileOutput, }); - return { - result: writeFileOutput, - status: "error", - }; + throw new Error(writeFileOutput); } let resultMessage = `Successfully applied diff to \`${file_path}\` and saved changes.`; diff --git a/apps/open-swe/src/tools/shell.ts b/apps/open-swe/src/tools/shell.ts index 3dcbc41a..6ace0f1d 100644 --- a/apps/open-swe/src/tools/shell.ts +++ b/apps/open-swe/src/tools/shell.ts @@ -62,10 +62,9 @@ export const shellTool = tool( error_result: response, input, }); - return { - result: `Command failed. Exit code: ${response.exitCode}\nResult: ${response.result}\nStdout:\n${response.artifacts?.stdout}`, - status: "error", - }; + throw new Error( + `Command failed. Exit code: ${response.exitCode}\nResult: ${response.result}\nStdout:\n${response.artifacts?.stdout}`, + ); } return { @@ -79,10 +78,9 @@ export const shellTool = tool( input, error: errorFields, }); - return { - result: `Command failed. Exit code: ${errorFields.exitCode}\nError: ${errorFields.result}\nStdout:\n${errorFields.artifacts?.stdout}`, - status: "error", - }; + throw new Error( + `Command failed. Exit code: ${errorFields.exitCode}\nError: ${errorFields.result}\nStdout:\n${errorFields.artifacts?.stdout}`, + ); } logger.error(