fix: throw errors in tools (#75)

* throw errors

* format

---------

Co-authored-by: bracesproul <braceasproul@gmail.com>
This commit is contained in:
Harrison Chase 2025-06-08 17:19:22 -07:00 • committed by GitHub
parent a0b8aaa075
commit d985ae4555
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 24 deletions

View file

@ -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.`;

View file

@ -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(