mcp_commune/
error.rs

1//! # Error Module
2//!
3//! This module defines the custom error types used throughout the Commune library.
4//! It provides a centralized way to handle and represent various error conditions
5//! that may occur during the operation of the library.
6
7use derive_more::Display;
8
9/// Represents the various error types that can occur in the Commune library.
10///
11/// This enum implements both `Debug` and `Display` traits for better error reporting.
12#[derive(Debug, Display)]
13pub enum Error {
14    /// Represents an internal server error.
15    #[display("internal server error")]
16    Internal,
17
18    /// Indicates that a requested feature is not supported.
19    #[display("unsupported feature")]
20    Unsupported,
21
22    /// Occurs when trying to use an uninitialized client.
23    #[display("uninitialized client")]
24    UninitializedClient,
25
26    /// Represents errors originating from the MCP client.
27    #[display("mcp client error")]
28    McpClient(String),
29
30    /// Indicates that a response received is invalid or cannot be processed.
31    #[display("invalid response")]
32    InvalidResponse,
33
34    /// Represents errors during serialization or deserialization processes.
35    #[display("serialization error")]
36    Serialization,
37
38    /// Occurs when there's an error initializing a client.
39    #[display("client initialization error")]
40    ClientInitialization,
41}
42
43/// Implements the standard error trait for our custom Error enum.
44///
45/// This allows our Error type to be used in contexts where a standard error is expected.
46impl std::error::Error for Error {}