Merge branch 'error-kind-notimp' into 'main'

Split up ErrorKind::NoSupport

See merge request tpo/core/arti!311
This commit is contained in:
Ian Jackson 2022-02-14 18:31:56 +00:00
commit 65e2deaf29
4 changed files with 32 additions and 15 deletions

View File

@ -159,16 +159,33 @@ pub enum ErrorKind {
/// A requested operation was not implemented by Arti.
///
/// This kind of error can happen when calling an API that isn't available
/// at runtime, or when requesting a piece of protocol functionality that is
/// not implemented.
/// This kind of error can happen when requesting a piece of protocol
/// functionality that has not (yet) been implemented in the Arti project.
///
/// If it happens as a result of a user activity, it's fine to ignore, log,
/// or report the error. If it happens as a result of direct API usage, it
/// may indicate that you're using something that isn't implemented yet, or
/// hasn't been turned on for your build environment.
#[display(fmt = "operation not supported")]
NoSupport,
/// may indicate that you're using something that isn't implemented yet.
///
/// This kind can relate both to operations which we plan to implement, and
/// to operations which we do not. It does not relate to faciities which
/// are disabled (e.g. at build time) or harmful.
///
/// It can refer to facilities which were once implemented in Tor or Arti
/// but for which support has been removed.
#[display(fmt = "operation not implemented")]
NotImplemented,
/// A feature was requested which has been disabled in this build of Arti.
///!
/// This kind of error happens when the running Arti was built wityout the
/// appropriate feature (usually, cargo feature) enabled.
///!
/// This might indicate that the overall running system has been
/// mis-configured at build-time. Alternatively, it can occur if the
/// running system is deliberately stripped down, in which case it might be
/// reasonable to simply report this error to a user.
#[display(fmt = "operation not supported because Arti feature disabled")]
FeatureDisabled,
/// Someone or something violated a network protocol.
///

View File

@ -31,8 +31,8 @@ pub enum Error {
/// The SOCKS client tried to use a SOCKS feature that we don't
/// support at all.
#[error("SOCKS feature not supported")]
NoSupport,
#[error("SOCKS feature not implemented")]
NotImplemented,
/// Tried to progress the SOCKS handshake when it was already
/// finished. This is a programming error.
@ -59,7 +59,7 @@ impl HasKind for Error {
}
E::Syntax | E::Decode(_) | E::BadProtocol(_) => EK::ProtocolViolation,
E::Invalid(_) => EK::BadArgument,
E::NoSupport => EK::NoSupport,
E::NotImplemented => EK::NotImplemented,
E::AlreadyFinished(_) => EK::Internal,
E::Internal(_) => EK::Internal,
}

View File

@ -180,7 +180,7 @@ impl SocksHandshake {
(State::Socks5Wait, [5, NO_AUTHENTICATION])
} else {
// In theory we should reply with "NO ACCEPTABLE METHODS".
return Err(Error::NoSupport);
return Err(Error::NotImplemented);
};
self.state = next;
@ -197,7 +197,7 @@ impl SocksHandshake {
let ver = r.take_u8()?;
if ver != 1 {
return Err(Error::NoSupport);
return Err(Error::NotImplemented);
}
let ulen = r.take_u8()?;
@ -445,7 +445,7 @@ mod test {
fn socks5_init_nothing_works() {
let mut h = SocksHandshake::new();
let a = h.handshake(&hex!("05 02 9988")[..]);
assert!(matches!(a, Ok(Err(Error::NoSupport))));
assert!(matches!(a, Ok(Err(Error::NotImplemented))));
}
#[test]

View File

@ -200,7 +200,7 @@ impl SocksRequest {
auth: SocksAuth,
) -> Result<Self> {
if !cmd.recognized() {
return Err(Error::NoSupport);
return Err(Error::NotImplemented);
}
if port == 0 && cmd.requires_port() {
return Err(Error::Syntax);
@ -298,7 +298,7 @@ mod test {
1024,
SocksAuth::NoAuth,
);
assert!(matches!(e, Err(Error::NoSupport)));
assert!(matches!(e, Err(Error::NotImplemented)));
let e = SocksRequest::new(
SocksVersion::V4,