Skip to content

Commit

Permalink
refactor!: Remove Result alias
Browse files Browse the repository at this point in the history
Now that there are several public error types, a single `Result` alias
doesn't really make sense. This also makes it easier to find and remove
`Error` references.

BREAKING CHANGE: The `Result` alias has been removed. It can be replaced
by `std::result::Result<T, qp2p::Error>`.
  • Loading branch information
Chris Connelly authored and connec committed Aug 27, 2021
1 parent 44d964c commit e528134
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::Endpoint;

use super::{
connection_pool::{ConnId, ConnectionPool, ConnectionRemover},
error::{ConnectionError, Error, RecvError, Result, SendError, SerializationError},
error::{ConnectionError, Error, RecvError, SendError, SerializationError},
wire_msg::WireMsg,
};
use bytes::Bytes;
Expand Down Expand Up @@ -263,7 +263,7 @@ async fn read_on_uni_streams(
uni_streams: &mut quinn::IncomingUniStreams,
peer_addr: SocketAddr,
message_tx: Sender<(SocketAddr, Bytes)>,
) -> Result<()> {
) -> Result<(), Error> {
while let Some(result) = uni_streams.next().await {
match result {
Err(error @ quinn::ConnectionError::ConnectionClosed(_)) => {
Expand Down Expand Up @@ -308,7 +308,7 @@ async fn read_on_bi_streams<I: ConnId>(
peer_addr: SocketAddr,
message_tx: Sender<(SocketAddr, Bytes)>,
endpoint: &Endpoint<I>,
) -> Result<()> {
) -> Result<(), Error> {
while let Some(result) = bi_streams.next().await {
match result {
Err(error @ quinn::ConnectionError::ConnectionClosed(_)) => {
Expand Down Expand Up @@ -379,7 +379,7 @@ async fn read_on_bi_streams<I: ConnId>(
async fn handle_endpoint_echo_req(
peer_addr: SocketAddr,
send_stream: &mut quinn::SendStream,
) -> Result<()> {
) -> Result<(), Error> {
trace!("Received Echo Request from peer {:?}", peer_addr);
let message = WireMsg::EndpointEchoResp(peer_addr);
message.write_to_stream(send_stream).await?;
Expand All @@ -392,7 +392,7 @@ async fn handle_endpoint_verification_req<I: ConnId>(
addr_sent: SocketAddr,
send_stream: &mut quinn::SendStream,
endpoint: &Endpoint<I>,
) -> Result<()> {
) -> Result<(), Error> {
trace!(
"Received Endpoint verification request {:?} from {:?}",
addr_sent,
Expand Down
8 changes: 4 additions & 4 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use super::{
DisconnectionEvents, RecvStream, SendStream,
},
error::{
ClientEndpointError, ConnectionError, EndpointError, RecvError, Result, RpcError,
SendError, SerializationError,
ClientEndpointError, ConnectionError, EndpointError, RecvError, RpcError, SendError,
SerializationError,
},
};
use backoff::{future::retry, ExponentialBackoff};
Expand Down Expand Up @@ -351,7 +351,7 @@ impl<I: ConnId> Endpoint<I> {
/// Verify if an address is publicly reachable. This will attempt to create
/// a new connection and use it to exchange a message and verify that the node
/// can be reached.
pub async fn is_reachable(&self, peer_addr: &SocketAddr) -> Result<()> {
pub async fn is_reachable(&self, peer_addr: &SocketAddr) -> Result<(), Error> {
trace!("Checking is reachable");
let connection = self.get_or_connect_to(peer_addr).await?;
let (mut send_stream, mut recv_stream) = connection.open_bi(0).await?;
Expand Down Expand Up @@ -413,7 +413,7 @@ impl<I: ConnId> Endpoint<I> {
msg: Bytes,
dest: &SocketAddr,
priority: i32,
) -> Result<()> {
) -> Result<(), Error> {
if let Some((conn, guard)) = self.connection_pool.get_by_addr(dest).await {
trace!("Connection exists in the connection pool: {}", dest);
let connection = Connection::new(conn, guard);
Expand Down
3 changes: 0 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ use bytes::Bytes;
use std::{fmt, io, net::SocketAddr};
use thiserror::Error;

/// Result used by `QuicP2p`.
pub type Result<T, E = Error> = std::result::Result<T, E>;

/// Error types returned by the qp2p public API.
#[derive(Debug, Error)]
#[non_exhaustive]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub use endpoint::{Endpoint, IncomingConnections, IncomingMessages};
pub use error::UpnpError;
pub use error::{
ClientEndpointError, Close, ConnectionError, EndpointError, Error, InternalConfigError,
RecvError, Result, RpcError, SendError, SerializationError, StreamError, TransportErrorCode,
RecvError, RpcError, SendError, SerializationError, StreamError, TransportErrorCode,
UnsupportedStreamOperation,
};

Expand Down
2 changes: 1 addition & 1 deletion src/wire_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Software.

use crate::{
error::{RecvError, Result, SendError, SerializationError},
error::{RecvError, SendError, SerializationError},
utils,
};
use bytes::Bytes;
Expand Down

0 comments on commit e528134

Please sign in to comment.