Skip to content

Commit b52fbcc

Browse files
committed
impl Display for errors
1 parent 5e9d20e commit b52fbcc

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

src/client/legacy/connect/proxy/socks/mod.rs

+21
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@ where
5757
}
5858
}
5959

60+
impl<C> std::fmt::Display for SocksError<C> {
61+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62+
f.write_str("SOCKS error: ")?;
63+
64+
match self {
65+
Self::Inner(_) => f.write_str("failed to create underlying connection"),
66+
Self::Io(_) => f.write_str("io error during SOCKS handshake"),
67+
68+
Self::DnsFailure => f.write_str("could not resolve to acceptable address type"),
69+
Self::MissingHost => f.write_str("missing destination host"),
70+
Self::MissingPort => f.write_str("missing destination port"),
71+
72+
Self::Parsing(_) => f.write_str("failed parsing server response"),
73+
Self::Serialize(_) => f.write_str("failed serialize request"),
74+
75+
Self::V4(e) => e.fmt(f),
76+
Self::V5(e) => e.fmt(f),
77+
}
78+
}
79+
}
80+
6081
impl<C> From<std::io::Error> for SocksError<C> {
6182
fn from(err: std::io::Error) -> Self {
6283
Self::Io(err)

src/client/legacy/connect/proxy/socks/v4/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ impl From<Status> for SocksV4Error {
1111
Self::Command(err)
1212
}
1313
}
14+
15+
impl std::fmt::Display for SocksV4Error {
16+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17+
match self {
18+
Self::IpV6 => f.write_str("IPV6 is not supported"),
19+
Self::Command(status) => status.fmt(f),
20+
}
21+
}
22+
}

src/client/legacy/connect/proxy/socks/v4/messages.rs

+11
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,14 @@ impl TryFrom<u8> for Status {
123123
})
124124
}
125125
}
126+
127+
impl std::fmt::Display for Status {
128+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
129+
f.write_str(match self {
130+
Self::Success => "success",
131+
Self::Failed => "server failed to execute command",
132+
Self::IdentFailure => "server ident service failed",
133+
Self::IdentMismatch => "server ident service did not recognise client identifier",
134+
})
135+
}
136+
}

src/client/legacy/connect/proxy/socks/v5/errors.rs

+20
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,23 @@ impl From<AuthError> for SocksV5Error {
2525
Self::Auth(err)
2626
}
2727
}
28+
29+
impl std::fmt::Display for SocksV5Error {
30+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31+
match self {
32+
Self::HostTooLong => f.write_str("host address is more than 255 characters"),
33+
Self::Command(e) => e.fmt(f),
34+
Self::Auth(e) => e.fmt(f),
35+
}
36+
}
37+
}
38+
39+
impl std::fmt::Display for AuthError {
40+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41+
f.write_str(match self {
42+
Self::Unsupported => "server does not support user/pass authentication",
43+
Self::MethodMismatch => "server implements authentication incorrectly",
44+
Self::Failed => "credentials not accepted",
45+
})
46+
}
47+
}

src/client/legacy/connect/proxy/socks/v5/messages.rs

+16
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,19 @@ impl TryFrom<u8> for AuthMethod {
329329
})
330330
}
331331
}
332+
333+
impl std::fmt::Display for Status {
334+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
335+
f.write_str(match self {
336+
Self::Success => "success",
337+
Self::GeneralServerFailure => "general server failure",
338+
Self::ConnectionNotAllowed => "connection not allowed",
339+
Self::NetworkUnreachable => "network unreachable",
340+
Self::HostUnreachable => "host unreachable",
341+
Self::ConnectionRefused => "connection refused",
342+
Self::TtlExpired => "ttl expired",
343+
Self::CommandNotSupported => "command not supported",
344+
Self::AddressTypeNotSupported => "address type not supported",
345+
})
346+
}
347+
}

0 commit comments

Comments
 (0)