feat: ToolError migration to ErrorData (#4051)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use chrono::Utc;
|
||||
use mcp_core::ToolError;
|
||||
use rmcp::model::Content;
|
||||
use rmcp::model::{Content, ErrorData};
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
@@ -8,8 +7,8 @@ const LARGE_TEXT_THRESHOLD: usize = 200_000;
|
||||
|
||||
/// Process tool response and handle large text content
|
||||
pub fn process_tool_response(
|
||||
response: Result<Vec<Content>, ToolError>,
|
||||
) -> Result<Vec<Content>, ToolError> {
|
||||
response: Result<Vec<Content>, ErrorData>,
|
||||
) -> Result<Vec<Content>, ErrorData> {
|
||||
match response {
|
||||
Ok(contents) => {
|
||||
let mut processed_contents = Vec::new();
|
||||
@@ -79,8 +78,8 @@ fn write_large_text_to_file(content: &str) -> Result<String, std::io::Error> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use mcp_core::ToolError;
|
||||
use rmcp::model::Content;
|
||||
use rmcp::model::{Content, ErrorCode, ErrorData};
|
||||
use std::borrow::Cow;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
@@ -213,8 +212,12 @@ mod tests {
|
||||
#[test]
|
||||
fn test_error_response_passes_through() {
|
||||
// Create an error response
|
||||
let error = ToolError::ExecutionError("Test error".to_string());
|
||||
let response: Result<Vec<Content>, ToolError> = Err(error);
|
||||
let error = ErrorData {
|
||||
code: ErrorCode::INTERNAL_ERROR,
|
||||
message: Cow::from("Test error"),
|
||||
data: None,
|
||||
};
|
||||
let response: Result<Vec<Content>, ErrorData> = Err(error);
|
||||
|
||||
// Process the response
|
||||
let processed = process_tool_response(response);
|
||||
@@ -222,8 +225,9 @@ mod tests {
|
||||
// Verify the error is passed through unchanged
|
||||
assert!(processed.is_err());
|
||||
match processed {
|
||||
Err(ToolError::ExecutionError(msg)) => {
|
||||
assert_eq!(msg, "Test error");
|
||||
Err(err) => {
|
||||
assert_eq!(err.code, ErrorCode::INTERNAL_ERROR);
|
||||
assert_eq!(err.message, "Test error");
|
||||
}
|
||||
_ => panic!("Expected execution error"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user