From c02ff1e47ef67929ab7f6526ba454e5547d3f180 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Thu, 7 Mar 2024 11:28:10 +0000 Subject: [PATCH] fetch: log handshake error When performing a handshake, the error source is hidden in the error variant and never shown. To get insight as to what the error was, it is logged when it is encounterd. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-fetch/src/lib.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/radicle-fetch/src/lib.rs b/radicle-fetch/src/lib.rs index d457ba81..071f6a7f 100644 --- a/radicle-fetch/src/lib.rs +++ b/radicle-fetch/src/lib.rs @@ -9,6 +9,7 @@ mod refs; mod stage; mod state; +use gix_protocol::handshake; pub use handle::Handle; pub use policy::{Allowed, BlockList, Scope}; use radicle::storage::ReadRepository as _; @@ -62,10 +63,7 @@ where if local == remote { return Err(Error::ReplicateSelf); } - let handshake = handle - .transport - .handshake() - .map_err(|err| Error::Handshake { err })?; + let handshake = perform_handshake(handle)?; let state = FetchState::default(); // N.b. ensure that we ignore the local peer's key. @@ -99,10 +97,7 @@ where if *handle.local() == remote { return Err(Error::ReplicateSelf); } - let handshake = handle - .transport - .handshake() - .map_err(|err| Error::Handshake { err })?; + let handshake = perform_handshake(handle)?; let state = FetchState::default(); let result = state .run(handle, &handshake, limit, remote, None) @@ -116,3 +111,13 @@ where ); result } + +fn perform_handshake(handle: &mut Handle) -> Result +where + S: transport::ConnectionStream, +{ + handle.transport.handshake().map_err(|err| { + log::warn!(target: "fetch", "Failed to perform handshake: {err}"); + Error::Handshake { err } + }) +}