Skip to content

Commit

Permalink
feat(cmd): improve error message
Browse files Browse the repository at this point in the history
The error message displayed in case of a missing Core Lightning configuration file has been enhanced to provide users with more friendly and actionable information.

Now, when coffee fails to find the configuration file at the specified path, it advises users to resolve the issue by running the coffee setup <cln_path> command, helping them quickly address the problem and proceed smoothly.

Signed-off-by: Tarek <tareknaser360@gmail.com>
  • Loading branch information
tareknaser committed Oct 19, 2023
1 parent f59756b commit 5e20bf5
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions coffee_core/src/coffee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use std::collections::HashMap;
use std::fmt::Debug;
use std::path::Path;
use std::vec::Vec;
use tokio::fs;

Expand Down Expand Up @@ -195,10 +196,24 @@ impl CoffeeManager {
if self.config.cln_config_path.is_none() {
return Ok(());
}
let root = self.config.cln_root.clone().unwrap();
let root = self
.config
.cln_root
.clone()
.ok_or_else(|| error!("cln root path not found, please run `coffee setup`"))?;
let rpc = Client::new(format!("{root}/{}/lightning-rpc", self.config.network));
self.rpc = Some(rpc);
let path = self.config.cln_config_path.clone().unwrap();
let path = self
.config
.cln_config_path
.clone()
.ok_or_else(|| error!("cln config path not found, please run `coffee setup`"))?;
// Ensure that the file exists
if !Path::new(&path).exists() {
return Err(error!(
"cln config path not found, please run `coffee setup`"
));
}
let mut file = CLNConf::new(path.clone(), true);
log::info!("looking for the cln config: {path}");
file.parse()
Expand All @@ -217,7 +232,10 @@ impl CoffeeManager {
self.config.cln_config_path = Some(path_with_network);
self.config.cln_root = Some(cln_dir.to_owned());
self.load_cln_conf().await?;
let mut conf = self.cln_config.clone().unwrap();
let mut conf = self
.cln_config
.clone()
.ok_or_else(|| error!("cln config path not found, please run `coffee setup`"))?;
conf.add_subconf(self.coffee_cln_config.clone())
.map_err(|err| error!("{}", &err.cause))?;
conf.flush()?;
Expand Down

0 comments on commit 5e20bf5

Please sign in to comment.