Skip to content
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
wants to merge 2 commits into from

Conversation

tareknaser
Copy link
Collaborator

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.

Fixes #209

@netlify
Copy link

netlify bot commented Oct 19, 2023

Deploy Preview for coffee-docs canceled.

Name Link
🔨 Latest commit 76ad241
🔍 Latest deploy log https://app.netlify.com/sites/coffee-docs/deploys/656eff3d5d703b0008e16297

Copy link
Contributor

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to go down this road, you should check if the path exists before create the CLNConf file.

coffee_core/src/coffee.rs Outdated Show resolved Hide resolved
coffee_core/src/coffee.rs Outdated Show resolved Hide resolved
coffee_core/src/coffee.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is wrong

coffee_core/src/coffee.rs Outdated Show resolved Hide resolved
The error message displayed in case of a missing Core Lightning configuration file has been enhanced to provide users with more friendly information.

Signed-off-by: Tarek <[email protected]>
Comment on lines +198 to +203
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."))?;
Copy link
Contributor

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next line is

let mut file = CLNConf::new(path.clone(), true);

where we set create_if_missing to true
This is what happens when the user first runs coffee

Copy link
Contributor

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 because CLNConf::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

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line will handle the case that the root path exists but the configuration file doesn't.

This is done already by CLNConf

Copy link
Collaborator Author

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 directory
2- 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.

Copy link
Contributor

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.

yes is does, you need to do CLNConf::new(path.clone(), false); if the file do not exist it return an error

What CLNConf handles is the case when ~/.lightning/bitcoin/config is missing but ~/.lightning/bitcoin exists.

Correct, you should check if the path exist

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 <[email protected]>
// 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();
Copy link
Contributor

Choose a reason for hiding this comment

The 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 /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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// SAFETY: We can unwrap here because we are sure that the path ends with /config

@vincenzopalazzo
Copy link
Contributor

I think this code should be simpler, and I try to see if this is true #220

@tareknaser
Copy link
Collaborator Author

Closing this pull request and going ahead with #220. It has the same fix but is simpler.

@tareknaser tareknaser closed this Dec 30, 2023
@tareknaser tareknaser deleted the better-error branch December 30, 2023 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

coffee is not able to recover from cln missing
2 participants