1use std::sync::mpsc::{RecvError, SendError};
2
3use thiserror::Error;
4
5pub type SshResult<I> = Result<I, SshError>;
6
7#[non_exhaustive]
8#[derive(Debug, Error)]
9pub enum SshError {
10 #[error("Version dismatch: {our} vs {their}")]
11 VersionDismatchError { our: String, their: String },
12 #[error("Key exchange error: {0}")]
13 KexError(String),
14 #[error("Parse ssh key error: {0}")]
15 SshPubKeyError(String),
16 #[error("Auth error")]
17 AuthError,
18 #[error("Timeout")]
19 TimeoutError,
20 #[error(transparent)]
21 DataFormatError(#[from] std::string::FromUtf8Error),
22 #[error("Encryption error: {0}")]
23 EncryptionError(String),
24 #[error("Compression error: {0}")]
25 CompressionError(String),
26 #[cfg(feature = "scp")]
27 #[error(transparent)]
28 SystemTimeError(#[from] std::time::SystemTimeError),
29 #[cfg(feature = "scp")]
30 #[error(transparent)]
31 ParseIntError(#[from] std::num::ParseIntError),
32 #[cfg(feature = "scp")]
33 #[error("Invalid scp file path")]
34 InvalidScpFilePath,
35 #[cfg(feature = "scp")]
36 #[error("Scp error: {0}")]
37 ScpError(String),
38 #[error(transparent)]
39 IoError(#[from] std::io::Error),
40 #[error("IPC error: {0}")]
41 IpcError(String),
42 #[error("Ssh Error: {0}")]
43 GeneralError(String),
44}
45
46impl From<RecvError> for SshError {
47 fn from(value: RecvError) -> Self {
48 Self::IpcError(value.to_string())
49 }
50}
51
52impl<T> From<SendError<T>> for SshError {
53 fn from(value: SendError<T>) -> Self {
54 Self::IpcError(value.to_string())
55 }
56}