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
This commit is contained in:
Roo Code 2025-09-08 21:41:09 +00:00
parent 7e65f6f6af
commit b34dc7c8de
8 changed files with 12 additions and 9 deletions

View file

@ -317,12 +317,15 @@ export async function presentAssistantMessage(cline: Task) {
return await askApproval("tool", toolMessage)
}
const handleError = async (action: string, error: Error) => {
const handleError = async (action: string, error: Error, title?: string) => {
const errorString = `Error ${action}: ${JSON.stringify(serializeError(error))}`
await cline.say(
"error",
`Error ${action}:\n${error.message ?? JSON.stringify(serializeError(error), null, 2)}`,
undefined,
undefined,
title ? { title } : undefined,
)
pushToolResult(formatResponse.toolError(errorString))

View file

@ -403,7 +403,7 @@ describe("writeToFileTool", () => {
await executeWriteFileTool({})
expect(mockHandleError).toHaveBeenCalledWith("writing file", expect.any(Error))
expect(mockHandleError).toHaveBeenCalledWith("writing file", expect.any(Error), "Write File Error")
expect(mockCline.diffViewProvider.reset).toHaveBeenCalled()
})
@ -412,7 +412,7 @@ describe("writeToFileTool", () => {
await executeWriteFileTool({}, { isPartial: true })
expect(mockHandleError).toHaveBeenCalledWith("writing file", expect.any(Error))
expect(mockHandleError).toHaveBeenCalledWith("writing file", expect.any(Error), "Write File Error")
expect(mockCline.diffViewProvider.reset).toHaveBeenCalled()
})
})

View file

@ -251,7 +251,7 @@ export async function applyDiffToolLegacy(
return
}
} catch (error) {
await handleError("applying diff", error)
await handleError("applying diff", error, "Apply Diff Error")
await cline.diffViewProvider.reset()
return
}

View file

@ -191,7 +191,7 @@ export async function insertContentTool(
await cline.diffViewProvider.reset()
} catch (error) {
handleError("insert content", error)
handleError("insert content", error, "Insert Content Error")
await cline.diffViewProvider.reset()
}
}

View file

@ -677,7 +677,7 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""}
pushToolResult(results.join("\n\n") + singleBlockNotice)
return
} catch (error) {
await handleError("applying diff", error)
await handleError("applying diff", error, "Apply Diff Error")
await cline.diffViewProvider.reset()
return
}

View file

@ -268,7 +268,7 @@ export async function searchAndReplaceTool(
cline.recordToolUsage("search_and_replace")
await cline.diffViewProvider.reset()
} catch (error) {
handleError("search and replace", error)
handleError("search and replace", error, "Search and Replace Error")
await cline.diffViewProvider.reset()
}
}

View file

@ -311,7 +311,7 @@ export async function writeToFileTool(
return
}
} catch (error) {
await handleError("writing file", error)
await handleError("writing file", error, "Write File Error")
await cline.diffViewProvider.reset()
return
}

View file

@ -11,7 +11,7 @@ export type AskApproval = (
forceApproval?: boolean,
) => Promise<boolean>
export type HandleError = (action: string, error: Error) => Promise<void>
export type HandleError = (action: string, error: Error, title?: string) => Promise<void>
export type PushToolResult = (content: ToolResponse) => void