-
Notifications
You must be signed in to change notification settings - Fork 951
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
core/: Add display implementation for DialError<THandler> #2456
Conversation
core/src/network.rs
Outdated
impl<THandler> fmt::Display for DialError<THandler> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{:?}", self) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Display
implementation of an error should be a nice string IMO. For most other errors in the codebase, we match on self
here and return something expressive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've implemented a prettier display implementation. The output for ConnectionLimit and LocalPeerId are inspired by the docs, but there was no description for InvalidPeerId, so I wrote something myself there, I hope that's okay, but would be happy with suggestions for something better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If PeerIds map one to one to multihashes, it might be cleaner to say "The dialing attempt was rejected because the PeerId was invalid" instead of what I wrote now. Let me know if you think that's better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks good to me, thank you!
@mxinden anything to add?
Thanks for the review. What's still curious to me though, is that the CI didn't catch this issue. In this run on the offending commit, Checking out that commit locally, and running |
I can not reproduce the failure locally either. Neither with current |
Also made a screen recording with some more info: debug.mp4 |
🤔 running cargo update fixed it for me on current upstream master, but that seems really strange. I don't know why it works now. I'd think that deriving debug shouldn't be possible if THandler doesn't implement debug? And I really don't understand why updating the dependencies with Anyways, if this all makes sense to you, I can transform this PR into one which derives debug again, but still adds the documentation string to InvalidPeerId, and provides a display impl through thiserror. |
Apparently it was a bug in thiserror: dtolnay/thiserror#79 No idea how I ended up with a thiserror version that old though. This PR now derives debug again, but still adds the docstring & provides a display implementation through thiserror. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thanks for bearing with us. Congrats on debugging the issue all the way upstream!
Would you mind including the merge commit and the changelog/version bump commit from https://github.com/mxinden/rust-libp2p/tree/display-dial-error here?
I rebased on your branch instead, I hope that's fine. Just cherry picking your last 3 commits resulted in a lot of merge conflicts. |
I triggered CI again. Let's see what it thinks :) |
Merged via #2473. @Frederik-Baetens would have pushed to your branch instead, but I don't seem to have permissions. |
Deriving debug was impossible because of THandler not having a Debug/Display trait bound on it. Adding that might be another way of solving this, but that seemed to require more extensive changes throughout the codebase.
This broke several examples, such as ipfs-kad. The problem seems to have been introduced in commit 74f31f1