Skip to content

Commit 80e950c

Browse files
authored
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)
1 parent a1a157c commit 80e950c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

crates/atuin-daemon/src/client.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use eyre::{eyre, Result};
1+
use eyre::{Context, Result};
22
#[cfg(windows)]
33
use tokio::net::TcpStream;
44
use tonic::transport::{Channel, Endpoint, Uri};
@@ -23,6 +23,7 @@ pub struct HistoryClient {
2323
impl HistoryClient {
2424
#[cfg(unix)]
2525
pub async fn new(path: String) -> Result<Self> {
26+
let log_path = path.clone();
2627
let channel = Endpoint::try_from("http://atuin_local_daemon:0")?
2728
.connect_with_connector(service_fn(move |_: Uri| {
2829
let path = path.clone();
@@ -32,7 +33,12 @@ impl HistoryClient {
3233
}
3334
}))
3435
.await
35-
.map_err(|_| eyre!("failed to connect to local atuin daemon. Is it running?"))?;
36+
.wrap_err_with(|| {
37+
format!(
38+
"failed to connect to local atuin daemon at {}. Is it running?",
39+
&log_path
40+
)
41+
})?;
3642

3743
let client = HistoryServiceClient::new(channel);
3844

@@ -50,7 +56,12 @@ impl HistoryClient {
5056
}
5157
}))
5258
.await
53-
.map_err(|_| eyre!("failed to connect to local atuin daemon. Is it running?"))?;
59+
.wrap_err_with(|| {
60+
format!(
61+
"failed to connect to local atuin daemon at 127.0.0.1:{}. Is it running?",
62+
port
63+
)
64+
})?;
5465

5566
let client = HistoryServiceClient::new(channel);
5667

0 commit comments

Comments
 (0)