pub enum Error {
Show 20 variants
Transport(TransportError),
Protocol(ProtocolError),
Serialization(Error),
InvalidRequest(String),
MethodNotFound(String),
InvalidParams(String),
Internal(String),
Cancelled,
Parse(String),
Server(String),
Client(String),
Timeout,
ConnectionClosed,
Io(Error),
UrlParse(ParseError),
Security(String),
Configuration(String),
ResourceAccess(String),
Validation(String),
Other(Error),
}
Expand description
Main error type for MoCoPr operations.
This enum covers all possible errors that can occur during MCP operations, from transport-level failures to protocol violations and application-level errors. Each error variant provides specific context about what went wrong.
§JSON-RPC Error Mapping
These errors can be mapped to JSON-RPC 2.0 error codes when sent over the wire:
InvalidRequest
→ -32600MethodNotFound
→ -32601InvalidParams
→ -32602Internal
→ -32603Parse
→ -32700
§Examples
use mocopr_core::error::{Error, ProtocolError};
// Create different types of errors
let transport_err = Error::ConnectionClosed;
let protocol_err = Error::Protocol(ProtocolError::ToolNotFound("my_tool".to_string()));
let validation_err = Error::InvalidParams("Missing required parameter 'path'".to_string());
Variants§
Transport(TransportError)
Transport layer error (connection, send/receive failures, etc.).
Protocol(ProtocolError)
Protocol layer error (capability negotiation, message sequencing, etc.).
Serialization(Error)
JSON serialization/deserialization error.
InvalidRequest(String)
The request is malformed or violates the protocol specification.
MethodNotFound(String)
The requested method/operation is not supported.
InvalidParams(String)
The provided parameters are invalid or missing required fields.
Internal(String)
An internal server error occurred.
Cancelled
The operation was cancelled by the user or system.
Parse(String)
Failed to parse message or data format.
Server(String)
Server-side error during request processing.
Client(String)
Client-side error in request formation or handling.
Timeout
Operation timed out.
ConnectionClosed
The connection was closed unexpectedly.
Io(Error)
Input/output error from the underlying system.
UrlParse(ParseError)
URL parsing failed.
Security(String)
Security-related error (authentication, authorization, validation).
Configuration(String)
Configuration error (invalid settings, missing config, etc.).
ResourceAccess(String)
Resource access error (file not found, permission denied, etc.).
Validation(String)
Validation error (schema validation, constraint violation, etc.).
Other(Error)
Catch-all for other error types.
Implementations§
Source§impl Error
impl Error
Sourcepub fn internal(msg: impl Into<String>) -> Self
pub fn internal(msg: impl Into<String>) -> Self
Create a new internal error.
§Examples
use mocopr_core::error::Error;
let error = Error::internal("Something went wrong internally");
Sourcepub fn transport(err: TransportError) -> Self
pub fn transport(err: TransportError) -> Self
Create a new transport error.
§Examples
use mocopr_core::error::{Error, TransportError};
let error = Error::transport(TransportError::ConnectionFailed("Network unreachable".to_string()));
Sourcepub fn protocol(err: ProtocolError) -> Self
pub fn protocol(err: ProtocolError) -> Self
Create a new protocol error.
§Examples
use mocopr_core::error::{Error, ProtocolError};
let error = Error::protocol(ProtocolError::ToolNotFound("missing_tool".to_string()));
Sourcepub fn security(msg: impl Into<String>) -> Self
pub fn security(msg: impl Into<String>) -> Self
Create a new security error.
§Examples
use mocopr_core::error::Error;
let error = Error::security("Invalid authentication token");
Sourcepub fn validation(msg: impl Into<String>) -> Self
pub fn validation(msg: impl Into<String>) -> Self
Create a new validation error.
§Examples
use mocopr_core::error::Error;
let error = Error::validation("Parameter 'path' must be an absolute path");
Sourcepub fn resource_access(msg: impl Into<String>) -> Self
pub fn resource_access(msg: impl Into<String>) -> Self
Create a new resource access error.
§Examples
use mocopr_core::error::Error;
let error = Error::resource_access("File not found: /path/to/file.txt");
Sourcepub fn method_not_found(method: impl Into<String>) -> Self
pub fn method_not_found(method: impl Into<String>) -> Self
Create a new method not found error.
§Examples
use mocopr_core::error::Error;
let error = Error::method_not_found("nonexistent_method");
Sourcepub fn invalid_params(msg: impl Into<String>) -> Self
pub fn invalid_params(msg: impl Into<String>) -> Self
Create a new invalid params error.
§Examples
use mocopr_core::error::Error;
let error = Error::invalid_params("Missing required parameter 'path'");
Sourcepub fn not_found(msg: impl Into<String>) -> Self
pub fn not_found(msg: impl Into<String>) -> Self
Create a new not found error.
§Examples
use mocopr_core::error::Error;
let error = Error::not_found("Resource not found");
Sourcepub fn operation_failed(msg: impl Into<String>) -> Self
pub fn operation_failed(msg: impl Into<String>) -> Self
Create a new operation failed error.
§Examples
use mocopr_core::error::Error;
let error = Error::operation_failed("Operation failed after multiple attempts");
Sourcepub fn resource_error(msg: impl Into<String>) -> Self
pub fn resource_error(msg: impl Into<String>) -> Self
Create a new resource error.
§Examples
use mocopr_core::error::Error;
let error = Error::resource_error("Failed to read file");
Sourcepub fn is_recoverable(&self) -> bool
pub fn is_recoverable(&self) -> bool
Check if the error is recoverable.
Recoverable errors are those that might succeed if retried, while non-recoverable errors indicate permanent failures.
§Examples
use mocopr_core::error::{Error, TransportError};
let timeout = Error::Timeout;
assert!(timeout.is_recoverable());
let closed = Error::ConnectionClosed;
assert!(!closed.is_recoverable());
Sourcepub fn json_rpc_code(&self) -> i32
pub fn json_rpc_code(&self) -> i32
Get the JSON-RPC error code for this error.
Maps MoCoPr errors to standard JSON-RPC 2.0 error codes.
§Examples
use mocopr_core::error::Error;
let error = Error::InvalidRequest("Malformed JSON".to_string());
assert_eq!(error.json_rpc_code(), -32600);
Sourcepub fn is_client_error(&self) -> bool
pub fn is_client_error(&self) -> bool
Check if this is a client-side error.
Client errors are those caused by invalid requests or client configuration.
§Examples
use mocopr_core::error::Error;
let client_error = Error::InvalidParams("Missing parameter".to_string());
assert!(client_error.is_client_error());
let server_error = Error::Internal("Database connection failed".to_string());
assert!(!server_error.is_client_error());
Trait Implementations§
Source§impl Error for Error
impl Error for Error
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<ParseError> for Error
impl From<ParseError> for Error
Source§fn from(source: ParseError) -> Self
fn from(source: ParseError) -> Self
Source§impl From<ProtocolError> for Error
impl From<ProtocolError> for Error
Source§fn from(source: ProtocolError) -> Self
fn from(source: ProtocolError) -> Self
Source§impl From<TransportError> for Error
impl From<TransportError> for Error
Source§fn from(source: TransportError) -> Self
fn from(source: TransportError) -> Self
Auto Trait Implementations§
impl Freeze for Error
impl !RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl !UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.