codeprism_mcp_server/
error.rs

1//! Error types for the CodePrism MCP Server
2
3use thiserror::Error;
4
5/// Result type alias for the MCP server
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Main error type for the CodePrism MCP Server
9#[derive(Error, Debug)]
10pub enum Error {
11    /// Configuration related errors
12    #[error("Configuration error: {0}")]
13    Config(#[from] config::ConfigError),
14
15    /// IO related errors
16    #[error("IO error: {0}")]
17    Io(#[from] std::io::Error),
18
19    /// JSON serialization/deserialization errors
20    #[error("JSON error: {0}")]
21    Json(#[from] serde_json::Error),
22
23    /// TOML serialization/deserialization errors
24    #[error("TOML error: {0}")]
25    Toml(#[from] toml::de::Error),
26
27    /// TOML serialization errors
28    #[error("TOML serialization error: {0}")]
29    TomlSer(#[from] toml::ser::Error),
30
31    /// YAML serialization/deserialization errors
32    #[error("YAML error: {0}")]
33    Yaml(#[from] serde_yaml::Error),
34
35    /// MCP protocol errors - will be defined when rust-sdk is added
36    #[error("MCP protocol error: {0}")]
37    Protocol(String),
38
39    /// Server initialization errors
40    #[error("Server initialization error: {0}")]
41    ServerInit(String),
42
43    /// Tool execution errors
44    #[error("Tool execution error: {0}")]
45    ToolExecution(String),
46
47    /// Generic errors
48    #[error("Internal error: {0}")]
49    Internal(#[from] anyhow::Error),
50}
51
52impl Error {
53    /// Create a new protocol error
54    pub fn protocol(msg: impl Into<String>) -> Self {
55        Self::Protocol(msg.into())
56    }
57
58    /// Create a new server initialization error
59    pub fn server_init(msg: impl Into<String>) -> Self {
60        Self::ServerInit(msg.into())
61    }
62
63    /// Create a new tool execution error
64    pub fn tool_execution(msg: impl Into<String>) -> Self {
65        Self::ToolExecution(msg.into())
66    }
67}