cnctd_service_ssh/
service_error.rs1use std::fmt;
6
7#[derive(Debug)]
9pub enum ServiceError {
10 InvalidParams(String),
12 NotFound(String),
14 Internal(String),
16 SerdeError(serde_json::Error),
18}
19
20impl fmt::Display for ServiceError {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 match self {
23 ServiceError::InvalidParams(msg) => write!(f, "Invalid parameters: {}", msg),
24 ServiceError::NotFound(msg) => write!(f, "Not found: {}", msg),
25 ServiceError::Internal(msg) => write!(f, "Internal error: {}", msg),
26 ServiceError::SerdeError(e) => write!(f, "Serialization error: {}", e),
27 }
28 }
29}
30
31impl std::error::Error for ServiceError {}
32
33impl From<serde_json::Error> for ServiceError {
34 fn from(err: serde_json::Error) -> Self {
35 ServiceError::SerdeError(err)
36 }
37}
38
39#[cfg(feature = "mcp")]
41impl From<ServiceError> for rmcp::model::ErrorData {
42 fn from(err: ServiceError) -> Self {
43 match err {
44 ServiceError::InvalidParams(msg) => {
45 rmcp::model::ErrorData::invalid_params(msg, None)
46 }
47 ServiceError::NotFound(msg) => {
48 rmcp::model::ErrorData::resource_not_found(msg, None)
49 }
50 ServiceError::Internal(msg) => {
51 rmcp::model::ErrorData::internal_error(msg, None)
52 }
53 ServiceError::SerdeError(e) => {
54 rmcp::model::ErrorData::internal_error(format!("JSON error: {}", e), None)
55 }
56 }
57 }
58}