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",
|
"tool_execution_failed",
|
||||||
&format!("{}: {}", tool_call.name, e),
|
&format!("{}: {}", tool_call.name, e),
|
||||||
);
|
);
|
||||||
ToolCallResult::from(Err(ErrorData::new(
|
// Try to downcast to ErrorData to avoid double wrapping
|
||||||
ErrorCode::INTERNAL_ERROR,
|
let error_data = e.downcast::<ErrorData>().unwrap_or_else(|e| {
|
||||||
e.to_string(),
|
ErrorData::new(ErrorCode::INTERNAL_ERROR, e.to_string(), None)
|
||||||
None,
|
});
|
||||||
)))
|
ToolCallResult::from(Err(error_data))
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1155,14 +1155,22 @@ impl ExtensionManager {
|
|||||||
self.get_client_for_tool(&prefixed_name)
|
self.get_client_for_tool(&prefixed_name)
|
||||||
.await
|
.await
|
||||||
.ok_or_else(|| {
|
.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
|
let tool_name = prefixed_name
|
||||||
.strip_prefix(client_name.as_str())
|
.strip_prefix(client_name.as_str())
|
||||||
.and_then(|s| s.strip_prefix("__"))
|
.and_then(|s| s.strip_prefix("__"))
|
||||||
.ok_or_else(|| {
|
.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();
|
.to_string();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user