Quit when the specified configuration is file not found. (#273)

Also, error on an invalid rpc certificate.
This commit is contained in:
David Hill 2016-06-27 15:00:48 -04:00 committed by Alex Yocom-Piatt
parent e6beeb689b
commit fee17a1a76
3 changed files with 10 additions and 14 deletions

View File

@ -215,7 +215,8 @@ func loadConfig() (*config, []string, error) {
parser := flags.NewParser(&cfg, flags.Default)
err = flags.NewIniParser(parser).ParseFile(preCfg.ConfigFile)
if err != nil {
if _, ok := err.(*os.PathError); !ok {
_, ok := err.(*os.PathError)
if !ok || preCfg.ConfigFile != cfg.ConfigFile {
fmt.Fprintf(os.Stderr, "Error parsing config file: %v\n",
err)
fmt.Fprintln(os.Stderr, usageMessage)

View File

@ -44,7 +44,10 @@ func newHTTPClient(cfg *config) (*http.Client, error) {
}
pool := x509.NewCertPool()
pool.AppendCertsFromPEM(pem)
if ok := pool.AppendCertsFromPEM(pem); !ok {
return nil, fmt.Errorf("invalid certificate file: %v",
cfg.RPCCert)
}
tlsConfig = &tls.Config{
RootCAs: pool,
InsecureSkipVerify: cfg.TLSSkipVerify,

View File

@ -412,20 +412,19 @@ func loadConfig() (*config, []string, error) {
}
// Load additional config from file.
var configFileError error
parser := newConfigParser(&cfg, &serviceOpts, flags.Default)
if !(preCfg.SimNet) || preCfg.ConfigFile !=
defaultConfigFile {
err := flags.NewIniParser(parser).ParseFile(preCfg.ConfigFile)
if err != nil {
if _, ok := err.(*os.PathError); !ok {
fmt.Fprintf(os.Stderr, "Error parsing config "+
"file: %v\n", err)
_, ok := err.(*os.PathError)
if !ok || preCfg.ConfigFile != defaultConfigFile {
fmt.Fprintf(os.Stderr, "Error parsing config file: %v\n",
err)
fmt.Fprintln(os.Stderr, usageMessage)
return nil, nil, err
}
configFileError = err
}
}
@ -868,13 +867,6 @@ func loadConfig() (*config, []string, error) {
}
}
// 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 {
dcrdLog.Warnf("%v", configFileError)
}
return &cfg, remainingArgs, nil
}