Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Better error reporting when features are disabled #2972

Merged
merged 39 commits into from
Nov 23, 2022
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f83ccea
Return `snow::Error` as source
thomaseizinger Oct 3, 2022
d64c216
Use `thiserror` macro to generate error
thomaseizinger Oct 3, 2022
9218c5d
Move `NoiseError` to `lib.rs`
thomaseizinger Oct 3, 2022
330e3ff
Be more specific about error case for bad signatures
thomaseizinger Oct 3, 2022
992706b
Be more specific about error case for unexpected key in authentication
thomaseizinger Oct 3, 2022
84ca840
Use `?` for better indentation
thomaseizinger Oct 3, 2022
b9ffed9
Even more use of `?`
thomaseizinger Oct 3, 2022
ae8b833
Use combinators on ALL the things
thomaseizinger Oct 3, 2022
e1c80e3
Be more specific about error case when validating key length
thomaseizinger Oct 3, 2022
3c15f9f
Include source of decoding error
thomaseizinger Oct 3, 2022
a937f16
Add changelog entry
thomaseizinger Oct 3, 2022
2531ab5
Slightly revise coding style of `ipfs-kad` example
thomaseizinger Oct 3, 2022
59ba1dd
Be more specific about what is not supported
thomaseizinger Oct 3, 2022
d789d5b
Don't include sources in Display impl
thomaseizinger Oct 3, 2022
097cf5e
Print source chain on `DialError`
thomaseizinger Oct 3, 2022
0826287
Format code
thomaseizinger Oct 4, 2022
5c5281f
Fix bad parenthesis
thomaseizinger Oct 4, 2022
76cdbbe
Fix clippy error
thomaseizinger Oct 4, 2022
c81f730
Introduce dedicated constructors for `DecodingError`
thomaseizinger Oct 5, 2022
18c5c02
Merge branch 'master' into 2971-better-error-message
mxinden Oct 5, 2022
fd870f8
Merge branch 'master' into 2971-better-error-message
mxinden Oct 5, 2022
682b363
Merge branch 'master' into 2971-better-error-message
mxinden Oct 9, 2022
f6017db
Merge branch 'master' into 2971-better-error-message
thomaseizinger Oct 11, 2022
1a49349
Merge branch 'master' into 2971-better-error-message
thomaseizinger Oct 14, 2022
7fc3c61
Merge branch 'master' into 2971-better-error-message
thomaseizinger Oct 19, 2022
db129cb
Bump version accordingly
thomaseizinger Oct 19, 2022
8a75a12
Merge branch 'master' into 2971-better-error-message
thomaseizinger Oct 24, 2022
513b920
Increase `libp2p-core` version to 0.37.1
thomaseizinger Oct 24, 2022
2fad2ac
Merge branch 'master' into 2971-better-error-message
mxinden Nov 2, 2022
3763ddf
Merge branch 'master' into 2971-better-error-message
thomaseizinger Nov 4, 2022
daaccd3
Merge branch 'master' into 2971-better-error-message
thomaseizinger Nov 15, 2022
b04b367
Fix bad boolean logic
thomaseizinger Nov 15, 2022
d8426bf
Merge branch 'master' into 2971-better-error-message
thomaseizinger Nov 17, 2022
2c348c6
Merge branch 'master' into 2971-better-error-message
thomaseizinger Nov 22, 2022
cedd5a1
Remove unnecessary feature activation
thomaseizinger Nov 22, 2022
47e3772
Revert "Remove unnecessary feature activation"
thomaseizinger Nov 22, 2022
7a7522b
Fix semver problem
thomaseizinger Nov 22, 2022
60d03f2
MOAR CONDITIONALS
thomaseizinger Nov 22, 2022
a549775
Fmt
thomaseizinger Nov 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 45 additions & 2 deletions swarm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1486,11 +1486,32 @@ impl fmt::Display for DialError {
f,
"Dial error: An I/O error occurred on the connection: {:?}.", e
),
DialError::Transport(e) => write!(f, "An error occurred while negotiating the transport protocol(s) on a connection: {:?}.", e),
DialError::Transport(errors) => {
write!(f, "Failed to negotiate transport protocol(s): [")?;

for (addr, error) in errors {
write!(f, "({addr})")?;
print_error_chain(f, error)?;
write!(f, ")")?;
}
write!(f, "]")?;

Ok(())
}
}
}
}

fn print_error_chain(f: &mut fmt::Formatter<'_>, e: &dyn error::Error) -> fmt::Result {
write!(f, ": {e}")?;

if let Some(source) = e.source() {
print_error_chain(f, source)?;
}

Ok(())
}

impl error::Error for DialError {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
Expand Down Expand Up @@ -1620,10 +1641,13 @@ mod tests {
use libp2p::core::{identity, multiaddr, transport, upgrade};
use libp2p::plaintext;
use libp2p::yamux;
use libp2p_core::either::EitherError;
use libp2p_core::multiaddr::multiaddr;
use libp2p_core::transport::memory::MemoryTransportError;
use libp2p_core::transport::TransportEvent;
use libp2p_core::Endpoint;
use libp2p_core::{Endpoint, UpgradeError};
use quickcheck::*;
use void::Void;

// Test execution state.
// Connection => Disconnecting => Connecting.
Expand Down Expand Up @@ -2502,4 +2526,23 @@ mod tests {
e => panic!("Unexpected swarm event {:?}.", e),
}
}

#[test]
fn dial_error_prints_sources() {
// This constitutes a fairly typical error for chained transports.
let error = DialError::Transport(vec![(
"/ip4/127.0.0.1/tcp/80".parse().unwrap(),
TransportError::Other(io::Error::new(
io::ErrorKind::Other,
EitherError::<_, Void>::A(EitherError::<Void, _>::B(UpgradeError::Apply(
MemoryTransportError::Unreachable,
))),
)),
)]);

let string = format!("{error}");

// Unfortunately, we have some "empty" errors that lead to multiple colons without text but that is the best we can do.
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
assert_eq!("Failed to negotiate transport protocol(s): [(/ip4/127.0.0.1/tcp/80): : Handshake failed: No listener on the given port.)]", string)
}
}