From a95d56741da0afdeb43fc97854e3c8d8c31722b6 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 19 Jun 2017 16:44:26 +0200 Subject: [PATCH] config: don't log to stderr if lnd.conf isn't found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes a bit of a wart in the configuration file handling wherein if the config file isn’t found, an error was printed to stderr. At times, this would cause the testing framework to erroneously mark as test as failed. Instead, we now keep a particular config file error, and check that, printing to a warning log level. --- config.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index 5045ffd8..782b6748 100644 --- a/config.go +++ b/config.go @@ -159,9 +159,10 @@ func loadConfig() (*config, error) { } // Next, load any additional configuration options from the file. + var configFileError error cfg := defaultCfg if err := flags.IniParse(preCfg.ConfigFile, &cfg); err != nil { - fmt.Fprintln(os.Stderr, err) + configFileError = err } // Finally, parse the remaining command line options again to ensure @@ -299,6 +300,13 @@ func loadConfig() (*config, error) { return nil, err } + // Warn about missing config file only after all other configuration is + // done. This prevents the warning on help messages and invalid + // options. Note this should go directly before the return. + if configFileError != nil { + ltndLog.Warnf("%v", configFileError) + } + return &cfg, nil }