Enum Error

Source
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 → -32600
  • MethodNotFound → -32601
  • InvalidParams → -32602
  • Internal → -32603
  • Parse → -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

Source

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");
Source

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()));
Source

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()));
Source

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");
Source

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");
Source

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");
Source

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");
Source

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'");
Source

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");
Source

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");
Source

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");
Source

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());
Source

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);
Source

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 Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<ParseError> for Error

Source§

fn from(source: ParseError) -> Self

Converts to this type from the input type.
Source§

impl From<ProtocolError> for Error

Source§

fn from(source: ProtocolError) -> Self

Converts to this type from the input type.
Source§

impl From<TransportError> for Error

Source§

fn from(source: TransportError) -> Self

Converts to this type from the input type.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,