Merge pull request #413 from Kixunil/config-file-error-handling

Improve error handling of config file
pull/418/head
Carla Kirk-Cohen 3 years ago committed by GitHub
commit 7ac6e26e90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -149,13 +149,16 @@ func Run(rpcCfg RPCConfig) error {
// Parse ini file.
loopDir := lncfg.CleanAndExpandPath(config.LoopDir)
configFile := getConfigPath(config, loopDir)
configFile, hasExplicitConfig := getConfigPath(config, loopDir)
if err := flags.IniParse(configFile, &config); err != nil {
// If it's a parsing related error, then we'll return
// immediately, otherwise we can proceed as possibly the config
// file doesn't exist which is OK.
if _, ok := err.(*flags.IniError); ok {
// File not existing is OK as long as it wasn't specified
// explicitly. All other errors (parsing, EACCESS...) indicate
// misconfiguration and need to be reported. In case of
// non-not-found FS errors there's high likelihood that other
// operations in data directory would also fail so we treat it
// as early detection of a problem.
if hasExplicitConfig || !os.IsNotExist(err) {
return err
}
}
@ -247,23 +250,24 @@ func Run(rpcCfg RPCConfig) error {
}
// getConfigPath gets our config path based on the values that are set in our
// config.
func getConfigPath(cfg Config, loopDir string) string {
// config. The returned bool is set to true if the config file path was set
// explicitly by the user and thus should not be ignored if it doesn't exist.
func getConfigPath(cfg Config, loopDir string) (string, bool) {
// If the config file path provided by the user is set, then we just
// use this value.
if cfg.ConfigFile != defaultConfigFile {
return lncfg.CleanAndExpandPath(cfg.ConfigFile)
return lncfg.CleanAndExpandPath(cfg.ConfigFile), true
}
// If the user has set a loop directory that is different to the default
// we will use this loop directory as the location of our config file.
// We do not namespace by network, because this is a custom loop dir.
if loopDir != LoopDirBase {
return filepath.Join(loopDir, defaultConfigFilename)
return filepath.Join(loopDir, defaultConfigFilename), false
}
// Otherwise, we are using our default loop directory, and the user did
// not set a config file path. We use our default loop dir, namespaced
// by network.
return filepath.Join(loopDir, cfg.Network, defaultConfigFilename)
return filepath.Join(loopDir, cfg.Network, defaultConfigFilename), false
}

@ -18,6 +18,14 @@ This file tracks release notes for the loop client.
#### Breaking Changes
* Failing to load configuration file specified by `--configfile` for any
reason is now hard error. If you've used `--configfile` to mean "optional
extra configuration" you will need to create an empty file. This was done in
[#413](https://github.com/lightninglabs/loop/pull/413) to improve error
reporting and avoid confusion. Similarly, failure to load any configuration
file for reason other than NotFound is hard error, though this is not strictly
breaking because such scenario would be already broken later.
#### Bug Fixes
#### Maintenance

Loading…
Cancel
Save