mirror of
https://github.com/aljazceru/goose.git
synced 2025-12-19 15:14:21 +01:00
Co-authored-by: Michael Neale <michael.neale@gmail.com> Co-authored-by: Wendy Tang <wendytang@squareup.com> Co-authored-by: Jarrod Sibbison <72240382+jsibbison-square@users.noreply.github.com> Co-authored-by: Alex Hancock <alex.hancock@example.com> Co-authored-by: Alex Hancock <alexhancock@block.xyz> Co-authored-by: Lifei Zhou <lifei@squareup.com> Co-authored-by: Wes <141185334+wesrblock@users.noreply.github.com> Co-authored-by: Max Novich <maksymstepanenko1990@gmail.com> Co-authored-by: Zaki Ali <zaki@squareup.com> Co-authored-by: Salman Mohammed <smohammed@squareup.com> Co-authored-by: Kalvin C <kalvinnchau@users.noreply.github.com> Co-authored-by: Alec Thomas <alec@swapoff.org> Co-authored-by: lily-de <119957291+lily-de@users.noreply.github.com> Co-authored-by: kalvinnchau <kalvin@block.xyz> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Rizel Scarlett <rizel@squareup.com> Co-authored-by: bwrage <bwrage@squareup.com> Co-authored-by: Kalvin Chau <kalvin@squareup.com> Co-authored-by: Alice Hau <110418948+ahau-square@users.noreply.github.com> Co-authored-by: Alistair Gray <ajgray@stripe.com> Co-authored-by: Nahiyan Khan <nahiyan.khan@gmail.com> Co-authored-by: Alex Hancock <alexhancock@squareup.com> Co-authored-by: Nahiyan Khan <nahiyan@squareup.com> Co-authored-by: marcelle <1852848+laanak08@users.noreply.github.com> Co-authored-by: Yingjie He <yingjiehe@block.xyz> Co-authored-by: Yingjie He <yingjiehe@squareup.com> Co-authored-by: Lily Delalande <ldelalande@block.xyz> Co-authored-by: Adewale Abati <acekyd01@gmail.com> Co-authored-by: Ebony Louis <ebony774@gmail.com> Co-authored-by: Angie Jones <jones.angie@gmail.com> Co-authored-by: Ebony Louis <55366651+EbonyLouis@users.noreply.github.com>
105 lines
2.7 KiB
Rust
105 lines
2.7 KiB
Rust
use thiserror::Error;
|
|
|
|
pub type BoxError = Box<dyn std::error::Error + Sync + Send>;
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum TransportError {
|
|
#[error("IO error: {0}")]
|
|
Io(#[from] std::io::Error),
|
|
|
|
#[error("JSON serialization error: {0}")]
|
|
Json(#[from] serde_json::Error),
|
|
|
|
#[error("Invalid UTF-8 sequence: {0}")]
|
|
Utf8(#[from] std::string::FromUtf8Error),
|
|
|
|
#[error("Protocol error: {0}")]
|
|
Protocol(String),
|
|
|
|
#[error("Invalid message format: {0}")]
|
|
InvalidMessage(String),
|
|
}
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum ServerError {
|
|
#[error("Transport error: {0}")]
|
|
Transport(#[from] TransportError),
|
|
|
|
#[error("Service error: {0}")]
|
|
Service(String),
|
|
|
|
#[error("Internal error: {0}")]
|
|
Internal(String),
|
|
|
|
#[error("Request timed out")]
|
|
Timeout(#[from] tower::timeout::error::Elapsed),
|
|
}
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum RouterError {
|
|
#[error("Method not found: {0}")]
|
|
MethodNotFound(String),
|
|
|
|
#[error("Invalid parameters: {0}")]
|
|
InvalidParams(String),
|
|
|
|
#[error("Internal error: {0}")]
|
|
Internal(String),
|
|
|
|
#[error("Tool not found: {0}")]
|
|
ToolNotFound(String),
|
|
|
|
#[error("Resource not found: {0}")]
|
|
ResourceNotFound(String),
|
|
|
|
#[error("Not found: {0}")]
|
|
PromptNotFound(String),
|
|
}
|
|
|
|
impl From<RouterError> for mcp_core::protocol::ErrorData {
|
|
fn from(err: RouterError) -> Self {
|
|
use mcp_core::protocol::*;
|
|
match err {
|
|
RouterError::MethodNotFound(msg) => ErrorData {
|
|
code: METHOD_NOT_FOUND,
|
|
message: msg,
|
|
data: None,
|
|
},
|
|
RouterError::InvalidParams(msg) => ErrorData {
|
|
code: INVALID_PARAMS,
|
|
message: msg,
|
|
data: None,
|
|
},
|
|
RouterError::Internal(msg) => ErrorData {
|
|
code: INTERNAL_ERROR,
|
|
message: msg,
|
|
data: None,
|
|
},
|
|
RouterError::ToolNotFound(msg) => ErrorData {
|
|
code: INVALID_REQUEST,
|
|
message: msg,
|
|
data: None,
|
|
},
|
|
RouterError::ResourceNotFound(msg) => ErrorData {
|
|
code: INVALID_REQUEST,
|
|
message: msg,
|
|
data: None,
|
|
},
|
|
RouterError::PromptNotFound(msg) => ErrorData {
|
|
code: INVALID_REQUEST,
|
|
message: msg,
|
|
data: None,
|
|
},
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<mcp_core::handler::ResourceError> for RouterError {
|
|
fn from(err: mcp_core::handler::ResourceError) -> Self {
|
|
match err {
|
|
mcp_core::handler::ResourceError::NotFound(msg) => RouterError::ResourceNotFound(msg),
|
|
_ => RouterError::Internal("Unknown resource error".to_string()),
|
|
}
|
|
}
|
|
}
|