From 76ad24136dd7891e94fe531dd7cbed3bbdd14d2b Mon Sep 17 00:00:00 2001 From: Tarek Date: Tue, 5 Dec 2023 12:45:00 +0200 Subject: [PATCH] fix(core): improve error message for missing lightning root folder This commit addresses the scenario where the lightning root folder is not found. Previously, Coffee would provide a generic error message (path not found), causing confusion. With this update, the error message has been refined to provide more clarity. Now, if the lightning root folder is not found, the error message specifically states: The path {lightning_path} does not exist. Signed-off-by: Tarek --- coffee_core/src/coffee.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/coffee_core/src/coffee.rs b/coffee_core/src/coffee.rs index ed271555..2d4908f9 100644 --- a/coffee_core/src/coffee.rs +++ b/coffee_core/src/coffee.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::fmt::Debug; +use std::path::Path; use std::vec::Vec; use tokio::fs; @@ -201,6 +202,17 @@ impl CoffeeManager { self.rpc = Some(rpc); let path = self.config.cln_config_path.clone(); let path = path.ok_or_else(|| error!("cln config path not found."))?; + + // The path is the path of the cln config file (eg. ~/.lightning/bitcoin/config) + // We need to check that the root folder (eg. ~/.lightning/bitcoin) exists + // otherwise we return an error. + + // We can unwrap here because we are sure that the path ends with /config + let lightning_path = path.strip_suffix("/config").unwrap(); + if !Path::new(&lightning_path).exists() { + return Err(error!("The path {lightning_path} does not exist")); + } + let mut file = CLNConf::new(path.clone(), true); log::info!("looking for the cln config: {path}"); file.parse()