feat: properly encapsulate quick_protobuf::Error

I noticed that we also still leak that dependency in several crates by providing a `From` impl so I've removed that one as well.

Resolves #3534.

Pull-Request: #3894.
This commit is contained in:
Thomas Eizinger
2023-05-12 04:26:01 +02:00
committed by GitHub
parent 6985d72462
commit 1bf6264cbe
7 changed files with 17 additions and 50 deletions

View File

@ -47,8 +47,6 @@ mod proto {
/// Multi-address re-export.
pub use multiaddr;
use std::fmt;
use std::fmt::Formatter;
pub type Negotiated<T> = multistream_select::Negotiated<T>;
#[deprecated(since = "0.39.0", note = "Depend on `libp2p-identity` instead.")]
@ -130,16 +128,5 @@ pub use transport::Transport;
pub use upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeError, UpgradeInfo};
#[derive(Debug, thiserror::Error)]
pub struct DecodeError(String);
impl From<quick_protobuf::Error> for DecodeError {
fn from(e: quick_protobuf::Error) -> Self {
Self(e.to_string())
}
}
impl fmt::Display for DecodeError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[error(transparent)]
pub struct DecodeError(quick_protobuf::Error);

View File

@ -36,8 +36,7 @@ impl PeerRecord {
let (payload, signing_key) =
envelope.payload_and_signing_key(String::from(DOMAIN_SEP), PAYLOAD_TYPE.as_bytes())?;
let mut reader = BytesReader::from_bytes(payload);
let record =
proto::PeerRecord::from_reader(&mut reader, payload).map_err(DecodeError::from)?;
let record = proto::PeerRecord::from_reader(&mut reader, payload).map_err(DecodeError)?;
let peer_id = PeerId::from_bytes(&record.peer_id)?;

View File

@ -97,8 +97,7 @@ impl SignedEnvelope {
use quick_protobuf::MessageRead;
let mut reader = BytesReader::from_bytes(bytes);
let envelope =
proto::Envelope::from_reader(&mut reader, bytes).map_err(DecodeError::from)?;
let envelope = proto::Envelope::from_reader(&mut reader, bytes).map_err(DecodeError)?;
Ok(Self {
key: PublicKey::try_decode_protobuf(&envelope.public_key)?,