-
Notifications
You must be signed in to change notification settings - Fork 676
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
fix: format tcp connection error using Display
#10286
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #10286 +/- ##
==========================================
- Coverage 71.81% 71.77% -0.05%
==========================================
Files 712 712
Lines 142878 142877 -1
Branches 142878 142877 -1
==========================================
- Hits 102611 102550 -61
- Misses 35559 35614 +55
- Partials 4708 4713 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Thanks for looking into this @itegulov! Looks good to me but just to double check, have you verified that this fixes the issue? |
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.
Yes, thank you!
@wacban thanks for keeping me honest! Apparently this only works if you are using alternate formatter. I have just pushed a fix and you can verify that this works by running the snippet below: #[tokio::test]
async fn test_tracing_debug() -> anyhow::Result<()> {
init_test_logger();
let peer_info = PeerInfo {
id: PeerId::random(),
// Non-routable IP address
addr: Some("10.255.255.1:3000".parse()?),
account_id: Some("fake.near".parse()?),
};
let result = async {
let _stream = tcp::Stream::connect(&peer_info, tcp::Tier::T2)
.await
.context("tcp::Stream::connect()")?;
anyhow::Ok(())
}
.await;
if let Err(ref err) = result {
tracing::info!(target:"network", err = format!("{:#}", err), "Failed to connect to {peer_info}");
}
Ok(())
} Expected output:
|
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.
Thanks, LGTM, even if the code isn't the prettiest we've exhausted other approaches. It's still better than having to deal with those annoying formatting in the stderr.
Please let me know if you need me a codeowner to get it merged and if it's ready and I'll press the button.
Reported by @wacban.
Debug printing results in multiline strings, which are hard to interpret. It also breaks tooling one might want to use to analyze logs.
Example:
I believe this is coming from the default
Debug
impl foranyhow::Error
. UsingDisplay
impl should fix it as it concatenates the context via:
instead.