mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 10:56:47 +00:00
Quit when the specified configuration is file not found. (#273)
Also, error on an invalid rpc certificate.
This commit is contained in:
parent
e6beeb689b
commit
fee17a1a76
@ -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)
|
||||
|
||||
@ -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,
|
||||
|
||||
16
config.go
16
config.go
@ -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
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user