Skip to content

Commit

Permalink
Deprecate HandlerError entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger committed Mar 23, 2023
1 parent 3163213 commit e28af53
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 28 deletions.
10 changes: 2 additions & 8 deletions protocols/gossipsub/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,10 @@ pub type PublishError = crate::error_priv::PublishError;
)]
pub type SubscriptionError = crate::error_priv::SubscriptionError;

#[deprecated(
since = "0.44.0",
note = "Use re-exports that omit `Gossipsub` prefix, i.e. `libp2p::gossipsub::HandlerError"
)]
#[deprecated(note = "This error will no longer be emitted")]
pub type GossipsubHandlerError = crate::error_priv::HandlerError;

#[deprecated(
since = "0.44.0",
note = "Use `libp2p::gossipsub::HandlerError` instead, as the `error` module will become crate-private in the future."
)]
#[deprecated(note = "This error will no longer be emitted")]
pub type HandlerError = crate::error_priv::HandlerError;

#[deprecated(
Expand Down
11 changes: 0 additions & 11 deletions protocols/gossipsub/src/error_priv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,14 @@ impl From<SigningError> for PublishError {
/// Errors that can occur in the protocols handler.
#[derive(Debug, Error)]
pub enum HandlerError {
#[deprecated(note = "This error will no longer be emitted")]
#[error("The maximum number of inbound substreams created has been exceeded.")]
MaxInboundSubstreams,
#[deprecated(note = "This error will no longer be emitted")]
#[error("The maximum number of outbound substreams created has been exceeded.")]
MaxOutboundSubstreams,
#[deprecated(note = "This error will no longer be emitted")]
#[error("The message exceeds the maximum transmission size.")]
MaxTransmissionSize,
#[deprecated(note = "This error will no longer be emitted")]
#[error("Protocol negotiation timeout.")]
NegotiationTimeout,
#[deprecated(note = "This error will no longer be emitted")]
#[error("Protocol negotiation failed.")]
NegotiationProtocolError(ProtocolError),
#[error("Failed to encode or decode")]
Expand Down Expand Up @@ -139,12 +134,6 @@ impl std::fmt::Display for ValidationError {

impl std::error::Error for ValidationError {}

impl From<std::io::Error> for HandlerError {
fn from(error: std::io::Error) -> HandlerError {
HandlerError::Codec(quick_protobuf_codec::Error::from(error))
}
}

impl From<std::io::Error> for PublishError {
fn from(error: std::io::Error) -> PublishError {
PublishError::TransformFailed(error)
Expand Down
4 changes: 2 additions & 2 deletions protocols/gossipsub/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use crate::protocol::{GossipsubCodec, ProtocolConfig};
use crate::rpc_proto::proto;
use crate::types::{PeerKind, RawMessage, Rpc};
use crate::{HandlerError, ValidationError};
use crate::ValidationError;
use asynchronous_codec::Framed;
use futures::prelude::*;
use futures::StreamExt;
Expand Down Expand Up @@ -238,7 +238,7 @@ impl Handler {
impl ConnectionHandler for Handler {
type InEvent = HandlerIn;
type OutEvent = HandlerEvent;
type Error = HandlerError;
type Error = crate::error_priv::HandlerError; // TODO: Replace this with `Void`.
type InboundOpenInfo = ();
type InboundProtocol = ProtocolConfig;
type OutboundOpenInfo = proto::RPC;
Expand Down
5 changes: 4 additions & 1 deletion protocols/gossipsub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,12 @@ mod types;

mod rpc_proto;

#[deprecated(note = "This error will no longer be emitted")]
pub type HandlerError = error_priv::HandlerError;

pub use self::behaviour::{Behaviour, Event, MessageAuthenticity};
pub use self::config::{Config, ConfigBuilder, ValidationMode, Version};
pub use self::error_priv::{HandlerError, PublishError, SubscriptionError, ValidationError};
pub use self::error_priv::{PublishError, SubscriptionError, ValidationError};
pub use self::peer_score::{
score_parameter_decay, score_parameter_decay_with_base, PeerScoreParams, PeerScoreThresholds,
TopicScoreParams,
Expand Down
12 changes: 6 additions & 6 deletions protocols/gossipsub/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use crate::topic::TopicHash;
use crate::types::{
ControlAction, MessageId, PeerInfo, PeerKind, RawMessage, Rpc, Subscription, SubscriptionAction,
};
use crate::ValidationError;
use crate::{rpc_proto::proto, Config};
use crate::{HandlerError, ValidationError};
use asynchronous_codec::{Decoder, Encoder, Framed};
use byteorder::{BigEndian, ByteOrder};
use bytes::BytesMut;
Expand Down Expand Up @@ -273,18 +273,18 @@ impl GossipsubCodec {

impl Encoder for GossipsubCodec {
type Item = proto::RPC;
type Error = HandlerError;
type Error = quick_protobuf_codec::Error;

fn encode(&mut self, item: Self::Item, dst: &mut BytesMut) -> Result<(), HandlerError> {
Ok(self.codec.encode(item, dst)?)
fn encode(&mut self, item: Self::Item, dst: &mut BytesMut) -> Result<(), Self::Error> {
self.codec.encode(item, dst)
}
}

impl Decoder for GossipsubCodec {
type Item = HandlerEvent;
type Error = HandlerError;
type Error = quick_protobuf_codec::Error;

fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, HandlerError> {
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
let rpc = match self.codec.decode(src)? {
Some(p) => p,
None => return Ok(None),
Expand Down

0 comments on commit e28af53

Please sign in to comment.