From 94a136c7227f6e9383cb17ce9ef9556f1d557867 Mon Sep 17 00:00:00 2001 From: chirag-bgh <76247491+chirag-bgh@users.noreply.github.com> Date: Wed, 6 Sep 2023 17:25:23 +0530 Subject: [PATCH] fix(swarm): better error message for failed `DialPeerCondition`s Closes #4407. Pull-Request: #4409. --- Cargo.lock | 2 +- Cargo.toml | 2 +- swarm/CHANGELOG.md | 7 +++++++ swarm/Cargo.toml | 2 +- swarm/src/lib.rs | 6 +++--- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2b74dfe84e0..5a345c62699 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3197,7 +3197,7 @@ dependencies = [ [[package]] name = "libp2p-swarm" -version = "0.43.3" +version = "0.43.4" dependencies = [ "async-std", "either", diff --git a/Cargo.toml b/Cargo.toml index 97c8c10adfa..189114f6ede 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -92,7 +92,7 @@ libp2p-relay = { version = "0.16.1", path = "protocols/relay" } libp2p-rendezvous = { version = "0.13.0", path = "protocols/rendezvous" } libp2p-request-response = { version = "0.25.1", path = "protocols/request-response" } 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-test = { version = "0.2.0", path = "swarm-test" } libp2p-tcp = { version = "0.40.0", path = "transports/tcp" } diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 37a5cbc6157..bc035893bd4 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -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 - Implement `Display` for `ConnectionId`. diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index c2b959eea01..b739aa8dabb 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-swarm" edition = "2021" rust-version = { workspace = true } description = "The libp2p swarm" -version = "0.43.3" +version = "0.43.4" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 867e49410c5..9ebbc12d907 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1580,9 +1580,9 @@ impl fmt::Display for DialError { f, "Dial error: tried to dial local peer id at {endpoint:?}." ), - DialError::DialPeerConditionFalse(c) => { - write!(f, "Dial error: condition {c:?} for dialing peer was false.") - } + 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."), + 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!( f, "Dial error: Pending connection attempt has been aborted."