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:
@@ -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))
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user