From 5b2f0de9cd2c6c88bffb20932ec8d2da74fd3f84 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Sat, 2 Sep 2023 17:11:54 -0300 Subject: [PATCH] cli: improve error message for holod connection failures Provide a more user-friendly error message when holo-cli can't connect to holod (usually due to holod not running). Signed-off-by: Renato Westphal --- holo-cli/src/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/holo-cli/src/main.rs b/holo-cli/src/main.rs index 2955f1c5..00d173f8 100644 --- a/holo-cli/src/main.rs +++ b/holo-cli/src/main.rs @@ -163,8 +163,14 @@ fn main() { // Initialize YANG context and gRPC client. let mut yang_ctx = yang::new_context(); - let mut client = - GrpcClient::connect(grpc_addr).expect("Failed to connect to holod"); + let mut client = match GrpcClient::connect(grpc_addr) { + Ok(client) => client, + Err(error) => { + eprintln!("Connection to holod failed : {}\n", error); + eprintln!("Please ensure that holod is currently running."); + std::process::exit(1); + } + }; client.load_modules(&mut yang_ctx); YANG_CTX.set(Arc::new(yang_ctx)).unwrap();