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

fix: format tcp connection error using Display #10286

Merged
merged 5 commits into from
Dec 4, 2023

Conversation

itegulov
Copy link
Contributor

@itegulov itegulov commented Dec 3, 2023

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:

2023-12-01T10:22:08.186809Z INFO network: failed to connect to ed25519:[email protected]:54063 result=Err(tcp::Stream::connect()
Caused by:
deadline has elapsed)

I believe this is coming from the default Debug impl for anyhow::Error. Using Display impl should fix it as it concatenates the context via : instead.

@itegulov itegulov requested a review from a team as a code owner December 3, 2023 23:12
@itegulov itegulov requested a review from nikurt December 3, 2023 23:12
Copy link

codecov bot commented Dec 3, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (b9ae299) 71.81% compared to head (2e0a41e) 71.77%.

Files Patch % Lines
...hain/network/src/peer_manager/network_state/mod.rs 0.00% 1 Missing and 1 partial ⚠️
...ain/network/src/peer_manager/peer_manager_actor.rs 50.00% 0 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
backward-compatibility 0.08% <0.00%> (ø)
db-migration 0.08% <0.00%> (ø)
genesis-check 1.25% <0.00%> (+<0.01%) ⬆️
integration-tests 36.14% <25.00%> (-0.06%) ⬇️
linux 71.64% <25.00%> (-0.05%) ⬇️
linux-nightly 71.35% <25.00%> (-0.03%) ⬇️
macos 55.45% <0.00%> (+0.44%) ⬆️
pytests 1.48% <0.00%> (+<0.01%) ⬆️
sanity-checks 1.28% <0.00%> (+<0.01%) ⬆️
unittests 68.14% <25.00%> (-0.02%) ⬇️
upgradability 0.13% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wacban
Copy link
Contributor

wacban commented Dec 4, 2023

Thanks for looking into this @itegulov! Looks good to me but just to double check, have you verified that this fixes the issue?

Copy link
Contributor

@nikurt nikurt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank you!

@itegulov
Copy link
Contributor Author

itegulov commented Dec 4, 2023

@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:

 1.001s  INFO network: Failed to connect to ed25519:[email protected]:[email protected] err="tcp::Stream::connect(): deadline has elapsed"

Copy link
Contributor

@wacban wacban left a 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.

@nikurt nikurt added this pull request to the merge queue Dec 4, 2023
Merged via the queue into master with commit 82544e1 Dec 4, 2023
14 of 16 checks passed
@nikurt nikurt deleted the daniyar/fmt-connect-anyhow branch December 4, 2023 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants