-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance Error Message for Missing Core Lightning Configuration File #211
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
use std::collections::HashMap; | ||
use std::fmt::Debug; | ||
use std::path::Path; | ||
use std::vec::Vec; | ||
use tokio::fs; | ||
|
||
|
@@ -195,10 +196,23 @@ 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(); | ||
let root = root.ok_or_else(|| error!("cln root path not found."))?; | ||
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(); | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
let lightning_path = path.strip_suffix("/config").unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you need to strip this, this means that you are checking in the wrong place. The check need to be done before we build the path with the |
||
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() | ||
|
@@ -217,7 +231,8 @@ 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 conf = self.cln_config.clone(); | ||
let mut conf = conf.ok_or_else(|| error!("cln config path not found."))?; | ||
conf.add_subconf(self.coffee_cln_config.clone()) | ||
.map_err(|err| error!("{}", &err.cause))?; | ||
conf.flush()?; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about the path is
Some
but do not exist?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The next line is
where we set
create_if_missing
totrue
This is what happens when the user first runs coffee
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mh I do not think this is right, if the
path
do not exist this code do not make sense becauseCLNConf::new(path.clone(), true);
is not able to find the path where to create the file.Please test the user case that I described #209
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right.
This line will handle the case that the root path exists but the configuration file doesn't.
However, it will fail if the root path doesn't exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added another check for this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done already by CLNConf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure
CLNConf
handles this case.Could you give it another try?
To reproduce:
1- delete
~/.lightning/bitcoin
directory2- try running coffee commands (eg.
coffee remote list
)You will get the same error mentioned in the original issue
What
CLNConf
handles is the case when~/.lightning/bitcoin/config
is missing but~/.lightning/bitcoin
exists.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes is does, you need to do
CLNConf::new(path.clone(), false);
if the file do not exist it return an errorCorrect, you should check if the
path
exist