use std::fmt;
use super::transport::{TransportContext, TransportErrorKind};
pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
#[derive(Debug)]
pub struct InvalidParamsDetails {
pub method: String,
pub message: String,
pub param_path: Option<String>,
pub expected: Option<String>,
pub actual: Option<String>,
pub source: Option<BoxError>,
}
impl fmt::Display for InvalidParamsDetails {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Invalid params for '{}': {}", self.method, self.message)
}
}
impl std::error::Error for InvalidParamsDetails {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.source
.as_ref()
.map(|e| e.as_ref() as &(dyn std::error::Error + 'static))
}
}
#[derive(Debug)]
pub struct TransportDetails {
pub kind: TransportErrorKind,
pub message: String,
pub context: TransportContext,
pub source: Option<BoxError>,
}
impl fmt::Display for TransportDetails {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Transport error ({}): {}", self.kind, self.message)
}
}
impl std::error::Error for TransportDetails {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.source
.as_ref()
.map(|e| e.as_ref() as &(dyn std::error::Error + 'static))
}
}
#[derive(Debug)]
pub struct ToolExecutionDetails {
pub tool: String,
pub message: String,
pub is_recoverable: bool,
pub data: Option<serde_json::Value>,
pub source: Option<BoxError>,
}
impl fmt::Display for ToolExecutionDetails {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Tool '{}' failed: {}", self.tool, self.message)
}
}
impl std::error::Error for ToolExecutionDetails {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.source
.as_ref()
.map(|e| e.as_ref() as &(dyn std::error::Error + 'static))
}
}
#[derive(Debug)]
pub struct HandshakeDetails {
pub message: String,
pub client_version: Option<String>,
pub server_version: Option<String>,
pub source: Option<BoxError>,
}
impl fmt::Display for HandshakeDetails {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Handshake failed: {}", self.message)
}
}
impl std::error::Error for HandshakeDetails {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.source
.as_ref()
.map(|e| e.as_ref() as &(dyn std::error::Error + 'static))
}
}