Skip to content

Commit

Permalink
fix: format tcp connection error using Display (#10286)
Browse files Browse the repository at this point in the history
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:AF4j@91.226.87.212: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.

---------

Co-authored-by: nikurt <86772482+nikurt@users.noreply.github.com>
  • Loading branch information
itegulov and nikurt authored Dec 4, 2023
1 parent b9ae299 commit 82544e1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions chain/network/src/peer_manager/network_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ impl NetworkState {

let succeeded = !result.is_err();

if result.is_err() {
tracing::info!(target:"network", ?result, "Failed to connect to {peer_info}");
if let Err(ref err) = result {
tracing::info!(target:"network", err = format!("{:#}", err), "Failed to connect to {peer_info}");
}

if self.peer_store.peer_connection_attempt(&clock, &peer_info.id, result).is_err() {
Expand Down
4 changes: 2 additions & 2 deletions chain/network/src/peer_manager/peer_manager_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ impl PeerManagerActor {
anyhow::Ok(())
}.await;

if result.is_err() {
tracing::info!(target:"network", ?result, "failed to connect to {peer_info}");
if let Err(ref err) = result {
tracing::info!(target: "network", err = format!("{:#}", err), "failed to connect to {peer_info}");
}
if state.peer_store.peer_connection_attempt(&clock, &peer_info.id, result).is_err() {
tracing::error!(target: "network", ?peer_info, "Failed to store connection attempt.");
Expand Down

0 comments on commit 82544e1

Please sign in to comment.