mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-19 04:42:34 +00:00
Improve transport connection errors (#4540)
## Issue Addressed #4538 ## Proposed Changes add newtype wrapper around DialError that extracts error messages and logs them in a more readable format ## Additional Info I was able to test Transport Dial Errors in the situation where a libp2p instance attempts to ping a nonexistent peer. That error message should look something like `A transport level error has ocurred: Connection refused (os error 61)` AgeManning mentioned we should try fetching only the most inner error (in situations where theres a nested error). I took a stab at implementing that For non transport DialErrors, I wrote out the error messages explicitly (as per the docs). Could potentially clean things up here if thats not necessary Co-authored-by: Age Manning <Age@AgeManning.com>
This commit is contained in:
@@ -17,6 +17,7 @@ pub mod rpc;
|
||||
pub mod types;
|
||||
|
||||
pub use config::gossip_max_size;
|
||||
use libp2p::swarm::DialError;
|
||||
pub use listen_addr::*;
|
||||
|
||||
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
|
||||
@@ -63,6 +64,46 @@ impl<'de> Deserialize<'de> for PeerIdSerialized {
|
||||
}
|
||||
}
|
||||
|
||||
// A wrapper struct that prints a dial error nicely.
|
||||
struct ClearDialError<'a>(&'a DialError);
|
||||
|
||||
impl<'a> ClearDialError<'a> {
|
||||
fn most_inner_error(err: &(dyn std::error::Error)) -> &(dyn std::error::Error) {
|
||||
let mut current = err;
|
||||
while let Some(source) = current.source() {
|
||||
current = source;
|
||||
}
|
||||
current
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> std::fmt::Display for ClearDialError<'a> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
|
||||
match &self.0 {
|
||||
DialError::Transport(errors) => {
|
||||
for (_, transport_error) in errors {
|
||||
match transport_error {
|
||||
libp2p::TransportError::MultiaddrNotSupported(multiaddr_error) => {
|
||||
write!(f, "Multiaddr not supported: {multiaddr_error}")?;
|
||||
}
|
||||
libp2p::TransportError::Other(other_error) => {
|
||||
let inner_error = ClearDialError::most_inner_error(other_error);
|
||||
write!(f, "Transport error: {inner_error}")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
DialError::LocalPeerId { .. } => write!(f, "The peer being dialed is the local peer."),
|
||||
DialError::NoAddresses => write!(f, "No addresses for the peer to dial."),
|
||||
DialError::DialPeerConditionFalse(_) => write!(f, "PeerCondition evaluation failed."),
|
||||
DialError::Aborted => write!(f, "Connection aborted."),
|
||||
DialError::WrongPeerId { .. } => write!(f, "Wrong peer id."),
|
||||
DialError::Denied { cause } => write!(f, "Connection denied: {:?}", cause),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub use crate::types::{
|
||||
error, Enr, EnrSyncCommitteeBitfield, GossipTopic, NetworkGlobals, PubsubMessage, Subnet,
|
||||
SubnetDiscovery,
|
||||
|
||||
Reference in New Issue
Block a user