From 80e950c648453f2b0fb5987ae01e3f24c7c819d9 Mon Sep 17 00:00:00 2001 From: Jeremy Cline Date: Wed, 2 Oct 2024 20:44:22 -0400 Subject: [PATCH] fix(daemon): Add context to error when unable to connect (#2394) Recently, it seems, the socket location for the daemon moved and this caused me to scratch my head briefly since I saw errors from the client connecting to the daemon, but the daemon was clearly running and the socket seemed to exist. This patch includes more context when the client fails to connect to the daemon. The path is included to help the user understand where the client was looking, and `wrap_err_with()` is used to show the user the cause of the error. This changes the error message from: Error: failed to connect to local atuin daemon. Is it running? to: Error: failed to connect to local atuin daemon at /run/user/1001/atuin.sock. Is it running? Caused by: 0: transport error 1: No such file or directory (os error 2) 2: No such file or directory (os error 2) --- crates/atuin-daemon/src/client.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/atuin-daemon/src/client.rs b/crates/atuin-daemon/src/client.rs index 815a71dc..110fd01a 100644 --- a/crates/atuin-daemon/src/client.rs +++ b/crates/atuin-daemon/src/client.rs @@ -1,4 +1,4 @@ -use eyre::{eyre, Result}; +use eyre::{Context, Result}; #[cfg(windows)] use tokio::net::TcpStream; use tonic::transport::{Channel, Endpoint, Uri}; @@ -23,6 +23,7 @@ pub struct HistoryClient { impl HistoryClient { #[cfg(unix)] pub async fn new(path: String) -> Result { + let log_path = path.clone(); let channel = Endpoint::try_from("http://atuin_local_daemon:0")? .connect_with_connector(service_fn(move |_: Uri| { let path = path.clone(); @@ -32,7 +33,12 @@ impl HistoryClient { } })) .await - .map_err(|_| eyre!("failed to connect to local atuin daemon. Is it running?"))?; + .wrap_err_with(|| { + format!( + "failed to connect to local atuin daemon at {}. Is it running?", + &log_path + ) + })?; let client = HistoryServiceClient::new(channel); @@ -50,7 +56,12 @@ impl HistoryClient { } })) .await - .map_err(|_| eyre!("failed to connect to local atuin daemon. Is it running?"))?; + .wrap_err_with(|| { + format!( + "failed to connect to local atuin daemon at 127.0.0.1:{}. Is it running?", + port + ) + })?; let client = HistoryServiceClient::new(channel);