diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -386,6 +386,13 @@ if (errMsg.isStr()) { strPrint += "error message:\n" + errMsg.get_str(); } + + if (errCode.isNum() && + errCode.get_int() == RPC_WALLET_NOT_SPECIFIED) { + strPrint += "\nTry adding " + "\"-rpcwallet=\" option to " + "bitcoin-cli command line."; + } } } else { // Result diff --git a/src/rpc/protocol.h b/src/rpc/protocol.h --- a/src/rpc/protocol.h +++ b/src/rpc/protocol.h @@ -109,6 +109,10 @@ RPC_WALLET_ENCRYPTION_FAILED = -16, //!< Wallet is already unlocked RPC_WALLET_ALREADY_UNLOCKED = -17, + //!< Invalid wallet specified + RPC_WALLET_NOT_FOUND = -18, + //!< No wallet specified (error when there are multiple wallets loaded) + RPC_WALLET_NOT_SPECIFIED = -19 }; UniValue JSONRPCRequestObj(const std::string &strMethod, const UniValue ¶ms, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -53,7 +53,7 @@ return pwallet; } } - throw JSONRPCError(RPC_INVALID_PARAMETER, + throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Requested wallet does not exist or is not loaded"); } return ::vpwallets.size() == 1 || (request.fHelp && ::vpwallets.size() > 0) @@ -77,7 +77,20 @@ return false; } - throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)"); + if (::vpwallets.empty()) { + // Note: It isn't currently possible to trigger this error because + // wallet RPC methods aren't registered unless a wallet is loaded. But + // this error is being kept as a precaution, because it's possible in + // the future that wallet RPC methods might get or remain registered + // when no wallets are loaded. + throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (wallet " + "method is disabled because " + "no wallet is loaded)"); + } + + throw JSONRPCError(RPC_WALLET_NOT_SPECIFIED, + "Wallet file not specified (must request wallet RPC " + "through /wallet/ uri-path)."); } void EnsureWalletIsUnlocked(CWallet *const pwallet) { diff --git a/test/functional/multiwallet.py b/test/functional/multiwallet.py --- a/test/functional/multiwallet.py +++ b/test/functional/multiwallet.py @@ -44,8 +44,12 @@ w1 = self.nodes[0] / "wallet/w1" w1.generate(1) + # accessing invalid wallet fails + assert_raises_jsonrpc(-18, "Requested wallet does not exist or is not loaded", + (self.nodes[0] / "wallet/bad").getwalletinfo) + # accessing wallet RPC without using wallet endpoint fails - assert_raises_jsonrpc(-32601, "Method not found", + assert_raises_jsonrpc(-19, "Method not found", self.nodes[0].getwalletinfo) # check w1 wallet balance