fix: Improve error messages for invalid tool calls (#6483)

Signed-off-by: J. Carr <jcarr250@protonmail.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Jason Carr
2026-01-14 07:14:34 -06:00
committed by GitHub
parent d923b323f8
commit 355d319bc4
2 changed files with 15 additions and 7 deletions
+5 -5
View File
@@ -529,11 +529,11 @@ impl Agent {
"tool_execution_failed",
&format!("{}: {}", tool_call.name, e),
);
ToolCallResult::from(Err(ErrorData::new(
ErrorCode::INTERNAL_ERROR,
e.to_string(),
None,
)))
// Try to downcast to ErrorData to avoid double wrapping
let error_data = e.downcast::<ErrorData>().unwrap_or_else(|e| {
ErrorData::new(ErrorCode::INTERNAL_ERROR, e.to_string(), None)
});
ToolCallResult::from(Err(error_data))
})
};
+10 -2
View File
@@ -1155,14 +1155,22 @@ impl ExtensionManager {
self.get_client_for_tool(&prefixed_name)
.await
.ok_or_else(|| {
ErrorData::new(ErrorCode::RESOURCE_NOT_FOUND, tool_call.name.clone(), None)
ErrorData::new(
ErrorCode::RESOURCE_NOT_FOUND,
format!("Tool '{}' not found", tool_call.name),
None,
)
})?;
let tool_name = prefixed_name
.strip_prefix(client_name.as_str())
.and_then(|s| s.strip_prefix("__"))
.ok_or_else(|| {
ErrorData::new(ErrorCode::RESOURCE_NOT_FOUND, tool_call.name.clone(), None)
ErrorData::new(
ErrorCode::RESOURCE_NOT_FOUND,
format!("Invalid tool name format: '{}'", tool_call.name),
None,
)
})?
.to_string();