Skip to content

Commit b34dc7c

Browse files
committed
feat: update handleError to accept optional title parameter
- Updated HandleError type to accept optional title parameter - Modified handleError function in presentAssistantMessage to pass title to say method - Added custom error titles to various tool error handlers - Updated tests to expect the new third parameter
1 parent 7e65f6f commit b34dc7c

File tree

8 files changed

+12
-9
lines changed

8 files changed

+12
-9
lines changed

src/core/assistant-message/presentAssistantMessage.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,15 @@ export async function presentAssistantMessage(cline: Task) {
317317
return await askApproval("tool", toolMessage)
318318
}
319319

320-
const handleError = async (action: string, error: Error) => {
320+
const handleError = async (action: string, error: Error, title?: string) => {
321321
const errorString = `Error ${action}: ${JSON.stringify(serializeError(error))}`
322322

323323
await cline.say(
324324
"error",
325325
`Error ${action}:\n${error.message ?? JSON.stringify(serializeError(error), null, 2)}`,
326+
undefined,
327+
undefined,
328+
title ? { title } : undefined,
326329
)
327330

328331
pushToolResult(formatResponse.toolError(errorString))

src/core/tools/__tests__/writeToFileTool.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ describe("writeToFileTool", () => {
403403

404404
await executeWriteFileTool({})
405405

406-
expect(mockHandleError).toHaveBeenCalledWith("writing file", expect.any(Error))
406+
expect(mockHandleError).toHaveBeenCalledWith("writing file", expect.any(Error), "Write File Error")
407407
expect(mockCline.diffViewProvider.reset).toHaveBeenCalled()
408408
})
409409

@@ -412,7 +412,7 @@ describe("writeToFileTool", () => {
412412

413413
await executeWriteFileTool({}, { isPartial: true })
414414

415-
expect(mockHandleError).toHaveBeenCalledWith("writing file", expect.any(Error))
415+
expect(mockHandleError).toHaveBeenCalledWith("writing file", expect.any(Error), "Write File Error")
416416
expect(mockCline.diffViewProvider.reset).toHaveBeenCalled()
417417
})
418418
})

src/core/tools/applyDiffTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export async function applyDiffToolLegacy(
251251
return
252252
}
253253
} catch (error) {
254-
await handleError("applying diff", error)
254+
await handleError("applying diff", error, "Apply Diff Error")
255255
await cline.diffViewProvider.reset()
256256
return
257257
}

src/core/tools/insertContentTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export async function insertContentTool(
191191

192192
await cline.diffViewProvider.reset()
193193
} catch (error) {
194-
handleError("insert content", error)
194+
handleError("insert content", error, "Insert Content Error")
195195
await cline.diffViewProvider.reset()
196196
}
197197
}

src/core/tools/multiApplyDiffTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""}
677677
pushToolResult(results.join("\n\n") + singleBlockNotice)
678678
return
679679
} catch (error) {
680-
await handleError("applying diff", error)
680+
await handleError("applying diff", error, "Apply Diff Error")
681681
await cline.diffViewProvider.reset()
682682
return
683683
}

src/core/tools/searchAndReplaceTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export async function searchAndReplaceTool(
268268
cline.recordToolUsage("search_and_replace")
269269
await cline.diffViewProvider.reset()
270270
} catch (error) {
271-
handleError("search and replace", error)
271+
handleError("search and replace", error, "Search and Replace Error")
272272
await cline.diffViewProvider.reset()
273273
}
274274
}

src/core/tools/writeToFileTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ export async function writeToFileTool(
311311
return
312312
}
313313
} catch (error) {
314-
await handleError("writing file", error)
314+
await handleError("writing file", error, "Write File Error")
315315
await cline.diffViewProvider.reset()
316316
return
317317
}

src/shared/tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type AskApproval = (
1111
forceApproval?: boolean,
1212
) => Promise<boolean>
1313

14-
export type HandleError = (action: string, error: Error) => Promise<void>
14+
export type HandleError = (action: string, error: Error, title?: string) => Promise<void>
1515

1616
export type PushToolResult = (content: ToolResponse) => void
1717

0 commit comments

Comments
 (0)