From 3a416735db508fab728269bed84accf0d2bb3822 Mon Sep 17 00:00:00 2001 From: Philip Patsch Date: Tue, 30 Jun 2020 04:39:55 +0200 Subject: [PATCH] =?UTF-8?q?ops/direnv:=20don=E2=80=99t=20ignore=20every=20?= =?UTF-8?q?connection=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We were throwing every single error that could be thrown by a varlink connection into a single bin, even though only one trivial case would mean the socket is not reachable. --- src/ops/direnv/mod.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ops/direnv/mod.rs b/src/ops/direnv/mod.rs index ffcdde5b..6b17d041 100644 --- a/src/ops/direnv/mod.rs +++ b/src/ops/direnv/mod.rs @@ -21,14 +21,22 @@ pub fn main(project: Project, mut shell_output: W) -> OpResul let address = crate::ops::get_paths()?.daemon_socket_address(); let shell_nix = rpc::ShellNix::try_from(&project.nix_file).map_err(ExitError::temporary)?; - let ping_sent = if let Ok(connection) = varlink::Connection::with_address(&address) { - use rpc::VarlinkClientInterface; - rpc::VarlinkClient::new(connection) - .watch_shell(shell_nix) - .call() - .is_ok() - } else { - false + let ping_sent = match varlink::Connection::with_address(&address) { + Ok(connection) => { + use rpc::VarlinkClientInterface; + rpc::VarlinkClient::new(connection) + .watch_shell(shell_nix) + .call() + .expect("unable to ping varlink server"); + true + } + Err(err) => match err.kind() { + // We cannot connect to the socket + varlink::error::ErrorKind::Io(std::io::ErrorKind::NotFound) => false, + varlink::error::ErrorKind::Io(std::io::ErrorKind::ConnectionRefused) => false, + // Any other error is probably a bug + _ => panic!("failed connecting to socket: {:?}", err), + }, }; match (ping_sent, paths_are_cached) {