From 484b12c0f3f7d3de21fa134cff7cc09e4431373f Mon Sep 17 00:00:00 2001 From: Patrick Walters Date: Wed, 21 Mar 2018 16:53:35 -0500 Subject: [PATCH] config: return proper daemon name for config errors Fix #915 by capturing the current daemonName and using that in error messages. --- config.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/config.go b/config.go index 44cb172c..e4c8e442 100644 --- a/config.go +++ b/config.go @@ -861,20 +861,27 @@ func parseRPCParams(cConfig *chainConfig, nodeConfig interface{}, net chainCode, if conf.RPCUser != "" && conf.RPCPass != "" { return nil } + + // Get the daemon name for displaying proper errors. + switch net { + case bitcoinChain: + daemonName = "btcd" + case litecoinChain: + daemonName = "ltcd" + } + // If only ONE of RPCUser or RPCPass is set, we assume the // user did that unintentionally. if conf.RPCUser != "" || conf.RPCPass != "" { return fmt.Errorf("please set both or neither of " + - "btcd.rpcuser and btcd.rpcpass") + "%[1]v.rpcuser, %[1]v.rpcpass", daemonName) } switch net { case bitcoinChain: - daemonName = "btcd" confDir = conf.Dir confFile = "btcd" case litecoinChain: - daemonName = "ltcd" confDir = conf.Dir confFile = "ltcd" } @@ -884,21 +891,27 @@ func parseRPCParams(cConfig *chainConfig, nodeConfig interface{}, net chainCode, if conf.RPCUser != "" && conf.RPCPass != "" && conf.ZMQPath != "" { return nil } + + // Get the daemon name for displaying proper errors. + switch net { + case bitcoinChain: + daemonName = "bitcoind" + case litecoinChain: + daemonName = "litecoind" + } // If only one or two of the parameters are set, we assume the // user did that unintentionally. if conf.RPCUser != "" || conf.RPCPass != "" || conf.ZMQPath != "" { return fmt.Errorf("please set all or none of " + - "bitcoind.rpcuser, bitcoind.rpcpass, and " + - "bitcoind.zmqpath") + "%[1]v.rpcuser, %[1]v.rpcpass, " + + "and %[1]v.zmqpath", daemonName) } switch net { case bitcoinChain: - daemonName = "bitcoind" confDir = conf.Dir confFile = "bitcoin" case litecoinChain: - daemonName = "litecoind" confDir = conf.Dir confFile = "litecoin" }