Skip to main content

do_memory_mcp/
error.rs

1//! Error types for MCP operations
2
3use thiserror::Error;
4
5/// Error type for MCP operations
6#[derive(Debug, Error)]
7pub enum Error {
8    /// Code execution error
9    #[error("Execution error: {0}")]
10    Execution(String),
11
12    /// Sandbox configuration error
13    #[error("Sandbox configuration error: {0}")]
14    Configuration(String),
15
16    /// Tool error
17    #[error("Tool error: {0}")]
18    Tool(String),
19
20    /// Security violation
21    #[error("Security violation: {0}")]
22    Security(String),
23
24    /// IO error
25    #[error("IO error: {0}")]
26    Io(#[from] std::io::Error),
27
28    /// JSON serialization error
29    #[error("Serialization error: {0}")]
30    Serialization(#[from] serde_json::Error),
31
32    /// General error
33    #[error("{0}")]
34    General(String),
35}
36
37/// Result type for MCP operations
38pub type Result<T> = std::result::Result<T, Error>;
39
40impl From<anyhow::Error> for Error {
41    fn from(err: anyhow::Error) -> Self {
42        Error::General(err.to_string())
43    }
44}
45
46impl From<String> for Error {
47    fn from(s: String) -> Self {
48        Error::General(s)
49    }
50}
51
52impl From<&str> for Error {
53    fn from(s: &str) -> Self {
54        Error::General(s.to_string())
55    }
56}