#[non_exhaustive]pub enum ServerError {
Show 19 variants
Protocol(Box<Error>),
Core(RegistryError),
Transport(TransportError),
Handler {
message: String,
context: Option<String>,
},
Configuration {
message: String,
key: Option<String>,
},
Authentication {
message: String,
method: Option<String>,
},
Authorization {
message: String,
resource: Option<String>,
},
RateLimit {
message: String,
retry_after: Option<u64>,
},
Lifecycle(String),
Shutdown(String),
Middleware {
name: String,
message: String,
},
Registry(String),
Routing {
message: String,
method: Option<String>,
},
NotFound {
resource: String,
},
Internal(String),
Io(Error),
Serialization(Error),
Timeout {
operation: String,
timeout_ms: u64,
},
ResourceExhausted {
resource: String,
current: Option<usize>,
max: Option<usize>,
},
}Expand description
Comprehensive server error types
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Protocol(Box<Error>)
Protocol-level error from client or protocol layer
This variant preserves the original protocol error, including error codes
like -1 for user rejection. This ensures transparency when forwarding
client errors (e.g., sampling/elicitation rejections) back through the
server to calling clients.
When converting to turbomcp_protocol::Error, this variant is unwrapped
directly to preserve error semantics and codes.
Core(RegistryError)
Core errors
Transport(TransportError)
Transport layer errors
Handler
Handler registration errors
Configuration
Configuration errors
Authentication
Authentication errors
Authorization
Authorization errors
RateLimit
Rate limiting errors
Lifecycle(String)
Server lifecycle errors
Shutdown(String)
Server shutdown errors
Middleware
Middleware errors
Registry(String)
Registry errors
Routing
Routing errors
NotFound
Resource not found
Internal(String)
Internal server errors
Io(Error)
IO errors
Serialization(Error)
Serialization errors
Timeout
Timeout errors
ResourceExhausted
Resource exhaustion
Implementations§
Source§impl ServerError
impl ServerError
Sourcepub fn handler_with_context(
message: impl Into<String>,
context: impl Into<String>,
) -> Self
pub fn handler_with_context( message: impl Into<String>, context: impl Into<String>, ) -> Self
Create a handler error with context
Sourcepub fn configuration(message: impl Into<String>) -> Self
pub fn configuration(message: impl Into<String>) -> Self
Create a new configuration error
Sourcepub fn configuration_with_key(
message: impl Into<String>,
key: impl Into<String>,
) -> Self
pub fn configuration_with_key( message: impl Into<String>, key: impl Into<String>, ) -> Self
Create a configuration error with key
Sourcepub fn authentication(message: impl Into<String>) -> Self
pub fn authentication(message: impl Into<String>) -> Self
Create a new authentication error
Sourcepub fn authentication_with_method(
message: impl Into<String>,
method: impl Into<String>,
) -> Self
pub fn authentication_with_method( message: impl Into<String>, method: impl Into<String>, ) -> Self
Create an authentication error with method
Create a new authorization error
Create an authorization error with resource
Sourcepub fn rate_limit(message: impl Into<String>) -> Self
pub fn rate_limit(message: impl Into<String>) -> Self
Create a new rate limit error
Sourcepub fn rate_limit_with_retry(
message: impl Into<String>,
retry_after: u64,
) -> Self
pub fn rate_limit_with_retry( message: impl Into<String>, retry_after: u64, ) -> Self
Create a rate limit error with retry after
Sourcepub fn middleware(name: impl Into<String>, message: impl Into<String>) -> Self
pub fn middleware(name: impl Into<String>, message: impl Into<String>) -> Self
Create a new middleware error
Sourcepub fn routing_with_method(
message: impl Into<String>,
method: impl Into<String>,
) -> Self
pub fn routing_with_method( message: impl Into<String>, method: impl Into<String>, ) -> Self
Create a routing error with method
Sourcepub fn resource_exhausted(resource: impl Into<String>) -> Self
pub fn resource_exhausted(resource: impl Into<String>) -> Self
Create a resource exhausted error
Sourcepub fn resource_exhausted_with_usage(
resource: impl Into<String>,
current: usize,
max: usize,
) -> Self
pub fn resource_exhausted_with_usage( resource: impl Into<String>, current: usize, max: usize, ) -> Self
Create a resource exhausted error with usage info
Sourcepub const fn is_retryable(&self) -> bool
pub const fn is_retryable(&self) -> bool
Check if this error is retryable
Sourcepub fn error_code(&self) -> i32
pub fn error_code(&self) -> i32
Get error code for JSON-RPC responses
Trait Implementations§
Source§impl Debug for ServerError
impl Debug for ServerError
Source§impl Display for ServerError
impl Display for ServerError
Source§impl Error for ServerError
impl Error for ServerError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<Error> for ServerError
impl From<Error> for ServerError
Source§impl From<Error> for ServerError
impl From<Error> for ServerError
Source§impl From<RegistryError> for ServerError
impl From<RegistryError> for ServerError
Source§fn from(source: RegistryError) -> Self
fn from(source: RegistryError) -> Self
Source§impl From<ServerError> for Box<Error>
This conversion preserves protocol errors directly when they come from clients
(ServerError::Protocol variant), ensuring error codes like -1 for user rejection
are maintained through the server layer.
impl From<ServerError> for Box<Error>
This conversion preserves protocol errors directly when they come from clients
(ServerError::Protocol variant), ensuring error codes like -1 for user rejection
are maintained through the server layer.
§Error Code Preservation
When a client returns an error (e.g., user rejects sampling with code -1),
the server receives it as ServerError::Protocol(Error{ kind: UserRejected }).
This conversion unwraps it directly, preserving the original error code when
the error is sent back to calling clients.