fix(swarm): better error message for failed DialPeerConditions

Closes #4407.

Pull-Request: #4409.
This commit is contained in:
chirag-bgh
2023-09-06 17:25:23 +05:30
committed by GitHub
parent 6f0895fee1
commit 94a136c722
5 changed files with 13 additions and 6 deletions

2
Cargo.lock generated
View File

@@ -3197,7 +3197,7 @@ dependencies = [
[[package]] [[package]]
name = "libp2p-swarm" name = "libp2p-swarm"
version = "0.43.3" version = "0.43.4"
dependencies = [ dependencies = [
"async-std", "async-std",
"either", "either",

View File

@@ -92,7 +92,7 @@ libp2p-relay = { version = "0.16.1", path = "protocols/relay" }
libp2p-rendezvous = { version = "0.13.0", path = "protocols/rendezvous" } libp2p-rendezvous = { version = "0.13.0", path = "protocols/rendezvous" }
libp2p-request-response = { version = "0.25.1", path = "protocols/request-response" } libp2p-request-response = { version = "0.25.1", path = "protocols/request-response" }
libp2p-server = { version = "0.12.2", path = "misc/server" } libp2p-server = { version = "0.12.2", path = "misc/server" }
libp2p-swarm = { version = "0.43.3", path = "swarm" } libp2p-swarm = { version = "0.43.4", path = "swarm" }
libp2p-swarm-derive = { version = "0.33.0", path = "swarm-derive" } libp2p-swarm-derive = { version = "0.33.0", path = "swarm-derive" }
libp2p-swarm-test = { version = "0.2.0", path = "swarm-test" } libp2p-swarm-test = { version = "0.2.0", path = "swarm-test" }
libp2p-tcp = { version = "0.40.0", path = "transports/tcp" } libp2p-tcp = { version = "0.40.0", path = "transports/tcp" }

View File

@@ -1,3 +1,10 @@
## 0.43.4 - unreleased
- Improve error message when `DialPeerCondition` prevents a dial.
See [PR 4409].
[PR 4409]: https://github.com/libp2p/rust-libp2p/pull/4409
## 0.43.3 ## 0.43.3
- Implement `Display` for `ConnectionId`. - Implement `Display` for `ConnectionId`.

View File

@@ -3,7 +3,7 @@ name = "libp2p-swarm"
edition = "2021" edition = "2021"
rust-version = { workspace = true } rust-version = { workspace = true }
description = "The libp2p swarm" description = "The libp2p swarm"
version = "0.43.3" version = "0.43.4"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT" license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p" repository = "https://github.com/libp2p/rust-libp2p"

View File

@@ -1580,9 +1580,9 @@ impl fmt::Display for DialError {
f, f,
"Dial error: tried to dial local peer id at {endpoint:?}." "Dial error: tried to dial local peer id at {endpoint:?}."
), ),
DialError::DialPeerConditionFalse(c) => { DialError::DialPeerConditionFalse(PeerCondition::Disconnected) => write!(f, "Dial error: dial condition was configured to only happen when disconnected (`PeerCondition::Disconnected`), but node is already connected, thus cancelling new dial."),
write!(f, "Dial error: condition {c:?} for dialing peer was false.") DialError::DialPeerConditionFalse(PeerCondition::NotDialing) => write!(f, "Dial error: dial condition was configured to only happen if there is currently no ongoing dialing attempt (`PeerCondition::NotDialing`), but a dial is in progress, thus cancelling new dial."),
} DialError::DialPeerConditionFalse(PeerCondition::Always) => unreachable!("Dial peer condition is by definition true."),
DialError::Aborted => write!( DialError::Aborted => write!(
f, f,
"Dial error: Pending connection attempt has been aborted." "Dial error: Pending connection attempt has been aborted."