mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-31 08:51:57 +00:00
Add protocol string to Error::UnknownProtocolString (#1355)
Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
This commit is contained in:
committed by
Pierre Krieger
parent
84b6a7d04d
commit
d83619109b
@@ -14,7 +14,7 @@ pub enum Error {
|
||||
InvalidUvar(decode::Error),
|
||||
ParsingError(Box<dyn error::Error + Send + Sync>),
|
||||
UnknownProtocolId(u32),
|
||||
UnknownProtocolString,
|
||||
UnknownProtocolString(String),
|
||||
#[doc(hidden)]
|
||||
__Nonexhaustive
|
||||
}
|
||||
@@ -28,7 +28,7 @@ impl fmt::Display for Error {
|
||||
Error::InvalidUvar(e) => write!(f, "failed to decode unsigned varint: {}", e),
|
||||
Error::ParsingError(e) => write!(f, "failed to parse: {}", e),
|
||||
Error::UnknownProtocolId(id) => write!(f, "unknown protocol id: {}", id),
|
||||
Error::UnknownProtocolString => f.write_str("unknown protocol string"),
|
||||
Error::UnknownProtocolString(string) => write!(f, "unknown protocol string: {}", string),
|
||||
Error::__Nonexhaustive => f.write_str("__Nonexhaustive")
|
||||
}
|
||||
}
|
||||
|
@@ -171,7 +171,7 @@ impl<'a> Protocol<'a> {
|
||||
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
|
||||
Ok(Protocol::Memory(s.parse()?))
|
||||
}
|
||||
_ => Err(Error::UnknownProtocolString)
|
||||
unknown => Err(Error::UnknownProtocolString(unknown.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -328,3 +328,15 @@ fn replace_ip4_with_ip6() {
|
||||
assert_eq!(result.unwrap(), "/ip6/2001:db8::1/tcp/10000".parse::<Multiaddr>().unwrap())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_protocol_string() {
|
||||
match "/unknown/1.2.3.4".parse::<Multiaddr>() {
|
||||
Ok(_) => assert!(false, "The UnknownProtocolString error should be caused"),
|
||||
Err(e) => match e {
|
||||
crate::Error::UnknownProtocolString(protocol) => {
|
||||
assert_eq!(protocol, "unknown")
|
||||
},
|
||||
_ => assert!(false, "The UnknownProtocolString error should be caused")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user