Provide, and use From impl for InternalError

Adding this autoconversion is quite safe since every error generation
site is explicit and has its own context, and we don't really need to
add more.

This simplifies the code and will simplify future work.
This commit is contained in:
Ian Jackson 2022-02-14 18:48:35 +00:00
parent 9e88f279d9
commit 4774cbd18d
2 changed files with 8 additions and 8 deletions

View File

@ -41,7 +41,7 @@ pub enum Error {
/// Something went wrong with the programming of this module.
#[error("Internal programming error while handling SOCKS handshake")]
Internal(InternalError),
Internal(#[from] InternalError),
}
// Note: at present, tor-socksproto isn't used in any settings where ErrorKind

View File

@ -113,10 +113,10 @@ impl SocksHandshake {
let mut r = Reader::from_slice(input);
let version = r.take_u8()?.try_into()?;
if version != SocksVersion::V4 {
return Err(Error::Internal(internal!(
return Err(internal!(
"called s4 on wrong type {:?}",
version
)));
).into());
}
let cmd: SocksCmd = r.take_u8()?.into();
@ -157,10 +157,10 @@ impl SocksHandshake {
let mut r = Reader::from_slice(input);
let version: SocksVersion = r.take_u8()?.try_into()?;
if version != SocksVersion::V5 {
return Err(Error::Internal(internal!(
return Err(internal!(
"called on wrong handshake type {:?}",
version
)));
).into());
}
/// Constant for Username/Password-style authentication.
@ -220,10 +220,10 @@ impl SocksHandshake {
let version: SocksVersion = r.take_u8()?.try_into()?;
if version != SocksVersion::V5 {
return Err(Error::Internal(internal!(
return Err(internal!(
"called s5 on non socks5 handshake with type {:?}",
version
)));
).into());
}
let cmd = r.take_u8()?.into();
let _ignore = r.take_u8()?;
@ -233,7 +233,7 @@ impl SocksHandshake {
let auth = self
.socks5_auth
.take()
.ok_or_else(|| Error::Internal(internal!("called s5 without negotiating auth")))?;
.ok_or_else(|| internal!("called s5 without negotiating auth"))?;
let request = SocksRequest::new(version, cmd, addr, port, auth)?;