1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum SshMcpError {
8 #[error("SSH connection error: {0}")]
10 Connection(String),
11
12 #[error("Authentication failed: {0}")]
14 Authentication(String),
15
16 #[error("Command timeout after {0}ms")]
18 Timeout(u64),
19
20 #[error("Invalid parameters: {0}")]
22 InvalidParams(String),
23
24 #[error("Elevation failed: {0}")]
26 ElevationFailed(String),
27
28 #[error("Configuration error: {0}")]
30 Config(String),
31
32 #[error("IO error: {0}")]
34 Io(#[from] std::io::Error),
35
36 #[error("SSH key error: {0}")]
38 SshKey(String),
39}
40
41pub type Result<T> = std::result::Result<T, SshMcpError>;
43
44impl SshMcpError {
45 pub fn connection(msg: impl Into<String>) -> Self {
47 SshMcpError::Connection(msg.into())
48 }
49
50 pub fn auth(msg: impl Into<String>) -> Self {
52 SshMcpError::Authentication(msg.into())
53 }
54
55 pub fn invalid_params(msg: impl Into<String>) -> Self {
57 SshMcpError::InvalidParams(msg.into())
58 }
59
60 pub fn elevation_failed(msg: impl Into<String>) -> Self {
62 SshMcpError::ElevationFailed(msg.into())
63 }
64
65 pub fn config(msg: impl Into<String>) -> Self {
67 SshMcpError::Config(msg.into())
68 }
69}
70
71#[cfg(test)]
72mod tests {
73 use super::*;
74
75 #[test]
76 fn test_error_display() {
77 let err = SshMcpError::Connection("failed to connect".to_string());
78 assert_eq!(err.to_string(), "SSH connection error: failed to connect");
79
80 let err = SshMcpError::Timeout(5000);
81 assert_eq!(err.to_string(), "Command timeout after 5000ms");
82 }
83}