tun2proxy/src/error.rs

78 lines
1.9 KiB
Rust
Raw Normal View History

#[derive(thiserror::Error, Debug)]
pub enum Error {
2023-03-25 21:12:41 +01:00
#[error("std::ffi::NulError {0:?}")]
Nul(#[from] std::ffi::NulError),
2023-09-26 18:25:59 +08:00
#[error(transparent)]
Io(#[from] std::io::Error),
2024-10-26 02:15:52 +08:00
#[cfg(unix)]
#[error("nix::errno::Errno {0:?}")]
NixErrno(#[from] nix::errno::Errno),
2023-08-22 15:24:05 +08:00
#[error("TryFromIntError {0:?}")]
TryFromInt(#[from] std::num::TryFromIntError),
#[error("std::net::AddrParseError {0}")]
AddrParse(#[from] std::net::AddrParseError),
2023-04-14 18:44:41 +08:00
#[error("std::str::Utf8Error {0:?}")]
Utf8(#[from] std::str::Utf8Error),
2023-08-06 13:48:56 +08:00
#[error("TryFromSliceError {0:?}")]
TryFromSlice(#[from] std::array::TryFromSliceError),
2024-02-01 19:15:32 +08:00
#[error("IpStackError {0:?}")]
IpStack(#[from] ipstack::IpStackError),
#[error("DnsProtoError {0:?}")]
2025-03-19 08:36:29 +08:00
DnsProto(#[from] hickory_proto::ProtoError),
2024-02-01 19:15:32 +08:00
#[error("httparse::Error {0:?}")]
Httparse(#[from] httparse::Error),
#[error("digest_auth::Error {0:?}")]
DigestAuth(#[from] digest_auth::Error),
2023-08-06 13:48:56 +08:00
2023-04-14 18:44:41 +08:00
#[cfg(target_os = "android")]
#[error("jni::errors::Error {0:?}")]
Jni(#[from] jni::errors::Error),
2023-07-21 14:42:55 +08:00
#[error("{0}")]
String(String),
#[error("std::num::ParseIntError {0:?}")]
IntParseError(#[from] std::num::ParseIntError),
2023-03-24 09:27:31 +08:00
}
impl From<&str> for Error {
fn from(err: &str) -> Self {
2023-07-21 14:42:55 +08:00
Self::String(err.to_string())
}
}
impl From<String> for Error {
fn from(err: String) -> Self {
Self::String(err)
}
}
impl From<&String> for Error {
fn from(err: &String) -> Self {
2023-07-21 14:42:55 +08:00
Self::String(err.to_string())
}
}
2023-07-21 14:42:55 +08:00
2023-09-26 18:25:59 +08:00
impl From<Error> for std::io::Error {
fn from(err: Error) -> Self {
match err {
Error::Io(err) => err,
_ => std::io::Error::new(std::io::ErrorKind::Other, err),
}
}
}
2024-02-12 21:36:18 +08:00
pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
2023-07-21 14:42:55 +08:00
pub type Result<T, E = Error> = std::result::Result<T, E>;