mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-07 08:26:51 +00:00
refactor(chat): avoid brittle parsing; map apply_diff param errors to localized diff error title
- Prefer t('chat:diffError.title') for apply_diff missing param messages
- Keep invalid JSON argument as 'Invalid Tool Arguments'
- Add stable tool-scoped fallbacks for other tools
- Update tests accordingly (45 passing)
This commit is contained in:
parent
001d38caad
commit
55f705326a
2 changed files with 26 additions and 12 deletions
|
|
@ -228,7 +228,8 @@ describe("extractErrorTitle", () => {
|
|||
|
||||
it("should handle missing required parameter tool error", () => {
|
||||
const error = "Roo tried to use apply_diff without value for required parameter 'path'. Retrying..."
|
||||
expect(extractErrorTitle(error, mockT)).toBe("Missing Required Parameter")
|
||||
// For apply_diff, prefer the same localized title used for diff_error in the chat
|
||||
expect(extractErrorTitle(error, mockT)).toBe("chat:diffError.title")
|
||||
})
|
||||
|
||||
it("should handle file not found error from actual code", () => {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,28 @@ export function extractErrorTitle(errorContent: string, t: TFunction): string {
|
|||
// Clean up the error content
|
||||
const trimmedContent = errorContent.trim()
|
||||
|
||||
// Special-case: if tool use is missing a required param for apply_diff, title as the diff error (localized).
|
||||
// Example: "Roo tried to use apply_diff without value for required parameter 'path'. Retrying..."
|
||||
const missingRequiredParamRe =
|
||||
/^Roo tried to use .+ without value for required parameter ['"“”‘’][^'"“”‘’]+['"“”‘’]/i
|
||||
const missingRequiredParamReFallback = /^Roo tried to use .+ without value for required parameter/i
|
||||
if (missingRequiredParamRe.test(trimmedContent) || missingRequiredParamReFallback.test(trimmedContent)) {
|
||||
return t("chat:diffError.title") // localized "Edit Unsuccessful"
|
||||
}
|
||||
|
||||
// For other tools, use stable tool-scoped titles that don't depend on message wording.
|
||||
const toolFailureTitles: Array<{ test: RegExp; title: string }> = [
|
||||
{ test: /\bsearch_and_replace\b/i, title: "Search & Replace Failure" },
|
||||
{ test: /\binsert_content\b/i, title: "Insert Content Failure" },
|
||||
{ test: /\bread_file\b/i, title: "Read File Failure" },
|
||||
{ test: /\bwrite_to_file\b/i, title: "Write File Failure" },
|
||||
]
|
||||
for (const { test, title } of toolFailureTitles) {
|
||||
if (test.test(trimmedContent)) {
|
||||
return title
|
||||
}
|
||||
}
|
||||
|
||||
// Define the type for error patterns
|
||||
type ErrorPattern = {
|
||||
pattern: RegExp
|
||||
|
|
@ -103,17 +125,8 @@ export function extractErrorTitle(errorContent: string, t: TFunction): string {
|
|||
pattern: /^Failed to apply diff:/i,
|
||||
title: "Diff Application Failed",
|
||||
},
|
||||
// Roo chat errors generated when tool args are missing/invalid
|
||||
{
|
||||
// Example: Roo tried to use apply_diff without value for required parameter 'path'. Retrying...
|
||||
pattern: /^Roo tried to use .+ without value for required parameter ['"“”‘’][^'"“”‘’]+['"“”‘’]/i,
|
||||
title: "Missing Required Parameter",
|
||||
},
|
||||
{
|
||||
// Fallback without quoting the param
|
||||
pattern: /^Roo tried to use .+ without value for required parameter/i,
|
||||
title: "Missing Required Parameter",
|
||||
},
|
||||
// Roo chat errors generated when tool args are missing/invalid (handled elsewhere for missing params)
|
||||
// Keep invalid JSON argument mapping here.
|
||||
]
|
||||
|
||||
// API and service error patterns
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue