Skip to content

Commit 832b2d6

Browse files
committed
fix: handle apply error for multi/single edit tools
1 parent be0c0d5 commit 832b2d6

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

gui/src/util/clientTools/multiEditImpl.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { resolveRelativePathInDir } from "core/util/ideUtils";
22
import { v4 as uuid } from "uuid";
3+
import { handleEditToolApplyError } from "../../redux/thunks/handleApplyStateUpdate";
34
import { ClientToolImpl } from "./callClientTool";
45

56
interface EditOperation {
@@ -117,13 +118,23 @@ export const multiEditImpl: ClientToolImpl = async (
117118
}
118119

119120
// Apply the changes to the file
120-
await extras.ideMessenger.request("applyToFile", {
121-
streamId,
122-
toolCallId,
123-
text: newContent,
124-
filepath: targetFilepath,
125-
isSearchAndReplace: true,
126-
});
121+
void extras.ideMessenger
122+
.request("applyToFile", {
123+
streamId,
124+
toolCallId,
125+
text: newContent,
126+
filepath: targetFilepath,
127+
isSearchAndReplace: true,
128+
})
129+
.then((res) => {
130+
if (res.status === "error") {
131+
void extras.dispatch(
132+
handleEditToolApplyError({
133+
toolCallId,
134+
}),
135+
);
136+
}
137+
});
127138

128139
// Return success - applyToFile will handle the completion state
129140
return {

gui/src/util/clientTools/singleFindAndReplaceImpl.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { resolveRelativePathInDir } from "core/util/ideUtils";
22
import { v4 as uuid } from "uuid";
3+
import { handleEditToolApplyError } from "../../redux/thunks/handleApplyStateUpdate";
34
import { ClientToolImpl } from "./callClientTool";
45

56
export const singleFindAndReplaceImpl: ClientToolImpl = async (
@@ -61,13 +62,23 @@ export const singleFindAndReplaceImpl: ClientToolImpl = async (
6162
}
6263

6364
// Apply the changes to the file
64-
await extras.ideMessenger.request("applyToFile", {
65-
streamId,
66-
toolCallId,
67-
text: newContent,
68-
filepath: resolvedFilepath,
69-
isSearchAndReplace: true,
70-
});
65+
void extras.ideMessenger
66+
.request("applyToFile", {
67+
streamId,
68+
toolCallId,
69+
text: newContent,
70+
filepath: resolvedFilepath,
71+
isSearchAndReplace: true,
72+
})
73+
.then((res) => {
74+
if (res.status === "error") {
75+
void extras.dispatch(
76+
handleEditToolApplyError({
77+
toolCallId,
78+
}),
79+
);
80+
}
81+
});
7182

7283
// Return success - applyToFile will handle the completion state
7384
return {

0 commit comments

Comments
 (0)