tun2proxy/src/error.rs

72 lines
1.8 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),
#[error("ctrlc::Error {0:?}")]
2023-03-25 21:52:58 +01:00
InterruptHandler(#[from] ctrlc::Error),
2023-03-25 21:12:41 +01:00
#[error("std::io::Error {0}")]
Io(#[from] std::io::Error),
#[error("std::net::AddrParseError {0}")]
AddrParse(#[from] std::net::AddrParseError),
#[error("smoltcp::iface::RouteTableFull {0:?}")]
RouteTableFull(#[from] smoltcp::iface::RouteTableFull),
2023-03-24 09:27:31 +08:00
#[error("smoltcp::socket::tcp::RecvError {0:?}")]
Recv(#[from] smoltcp::socket::tcp::RecvError),
2023-03-24 14:31:22 +08:00
#[error("smoltcp::socket::tcp::ListenError {0:?}")]
Listen(#[from] smoltcp::socket::tcp::ListenError),
2023-03-24 14:31:22 +08:00
#[error("smoltcp::socket::udp::BindError {0:?}")]
Bind(#[from] smoltcp::socket::udp::BindError),
2023-03-24 14:31:22 +08:00
#[error("smoltcp::socket::tcp::SendError {0:?}")]
2023-03-25 21:52:58 +01:00
Send(#[from] smoltcp::socket::tcp::SendError),
2023-03-24 14:31:22 +08:00
2023-04-14 18:44:41 +08:00
#[error("std::str::Utf8Error {0:?}")]
Utf8(#[from] std::str::Utf8Error),
#[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("nix::errno::Errno {0:?}")]
OSError(#[from] nix::errno::Errno),
#[error("std::num::ParseIntError {0:?}")]
IntParseError(#[from] std::num::ParseIntError),
2023-06-22 13:09:36 -04:00
#[error("httparse::Error {0}")]
HttpError(#[from] httparse::Error),
#[error("digest_auth::Error {0}")]
DigestAuthError(#[from] digest_auth::Error),
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
pub type Result<T, E = Error> = std::result::Result<T, E>;