Skip to content

Commit

Permalink
fix(daemon): Add context to error when unable to connect (#2394)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
jeremycline authored Oct 3, 2024
1 parent a1a157c commit 80e950c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions crates/atuin-daemon/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use eyre::{eyre, Result};
use eyre::{Context, Result};
#[cfg(windows)]
use tokio::net::TcpStream;
use tonic::transport::{Channel, Endpoint, Uri};
Expand All @@ -23,6 +23,7 @@ pub struct HistoryClient {
impl HistoryClient {
#[cfg(unix)]
pub async fn new(path: String) -> Result<Self> {
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();
Expand All @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit 80e950c

Please sign in to comment.