diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-09-21 18:10:06 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-09-21 18:10:06 +0800 |
| commit | c730a220232d6343e50aadc6d6c37b308215e401 (patch) | |
| tree | 652d4ca91c4eb4cc935fc796ccd4f39e86da1777 /crates/utils | |
| parent | f978525bfc600d609f54b23e161c64c2a1eeffa2 (diff) | |
Update TcpTargetError
Diffstat (limited to 'crates/utils')
| -rw-r--r-- | crates/utils/tcp_connection/src/error.rs | 91 |
1 files changed, 78 insertions, 13 deletions
diff --git a/crates/utils/tcp_connection/src/error.rs b/crates/utils/tcp_connection/src/error.rs index 02f96e3..171e23d 100644 --- a/crates/utils/tcp_connection/src/error.rs +++ b/crates/utils/tcp_connection/src/error.rs @@ -1,24 +1,89 @@ -#[derive(Default, Clone, Eq, PartialEq)] -pub struct TcpTargetError { - msg: String, +use std::io; +use thiserror::Error; + +#[derive(Error, Debug, Clone)] +pub enum TcpTargetError { + #[error("I/O error: {0}")] + Io(String), + + #[error("Serialization error: {0}")] + Serialization(String), + + #[error("Cryptographic error: {0}")] + Crypto(String), + + #[error("Protocol error: {0}")] + Protocol(String), + + #[error("Authentication failed: {0}")] + Authentication(String), + + #[error("File operation error: {0}")] + File(String), + + #[error("Network error: {0}")] + Network(String), + + #[error("Invalid configuration: {0}")] + Config(String), + + #[error("Timeout: {0}")] + Timeout(String), + + #[error("Unsupported operation: {0}")] + Unsupported(String), } -impl<'a> std::fmt::Display for TcpTargetError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.msg) +impl From<io::Error> for TcpTargetError { + fn from(error: io::Error) -> Self { + TcpTargetError::Io(error.to_string()) } } -impl<'a> From<&'a str> for TcpTargetError { - fn from(value: &'a str) -> Self { - Self { - msg: value.to_string(), - } +impl From<serde_json::Error> for TcpTargetError { + fn from(error: serde_json::Error) -> Self { + TcpTargetError::Serialization(error.to_string()) } } -impl<'a> From<String> for TcpTargetError { +impl From<&str> for TcpTargetError { + fn from(value: &str) -> Self { + TcpTargetError::Protocol(value.to_string()) + } +} + +impl From<String> for TcpTargetError { fn from(value: String) -> Self { - Self { msg: value } + TcpTargetError::Protocol(value) + } +} + +impl From<rsa::errors::Error> for TcpTargetError { + fn from(error: rsa::errors::Error) -> Self { + TcpTargetError::Crypto(error.to_string()) + } +} + +impl From<ed25519_dalek::SignatureError> for TcpTargetError { + fn from(error: ed25519_dalek::SignatureError) -> Self { + TcpTargetError::Crypto(error.to_string()) + } +} + +impl From<ring::error::Unspecified> for TcpTargetError { + fn from(error: ring::error::Unspecified) -> Self { + TcpTargetError::Crypto(error.to_string()) + } +} + +impl From<base64::DecodeError> for TcpTargetError { + fn from(error: base64::DecodeError) -> Self { + TcpTargetError::Serialization(error.to_string()) + } +} + +impl From<pem::PemError> for TcpTargetError { + fn from(error: pem::PemError) -> Self { + TcpTargetError::Crypto(error.to_string()) } } |
