From 7f4b2a43da7e6e081b648ef912b564215dfdd945 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Thu, 8 Apr 2021 14:04:09 +0200 Subject: [PATCH] [RPC] Return method name with 'Method not found' errors --- src/rpc/mining.cpp | 5 ++--- src/rpc/server.cpp | 2 +- test/functional/wallet_disable.py | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index d1f2ce630ed81..4fc4c257b255c 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -233,8 +233,7 @@ UniValue setgenerate(const JSONRPCRequest& request) "\nTurn off generation\n" + HelpExampleCli("setgenerate", "false") + "\nUsing json rpc\n" + HelpExampleRpc("setgenerate", "true, 1")); - if (pwalletMain == NULL) - throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)"); + EnsureWallet(); if (Params().IsRegTestNet()) throw JSONRPCError(RPC_INVALID_REQUEST, "Use the generate method instead of setgenerate on regtest"); @@ -832,4 +831,4 @@ void RegisterMiningRPCCommands(CRPCTable &tableRPC) { for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]); -} \ No newline at end of file +} diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 754c27e135ea4..482b317d8b324 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -430,7 +430,7 @@ UniValue CRPCTable::execute(const JSONRPCRequest &request) const // Find method const CRPCCommand* pcmd = tableRPC[request.strMethod]; if (!pcmd) - throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found"); + throw JSONRPCError(RPC_METHOD_NOT_FOUND, strprintf("Method not found: %s", request.strMethod)); g_rpcSignals.PreCommand(*pcmd); diff --git a/test/functional/wallet_disable.py b/test/functional/wallet_disable.py index 2e1057737592f..a2ef758eb6511 100755 --- a/test/functional/wallet_disable.py +++ b/test/functional/wallet_disable.py @@ -19,7 +19,7 @@ def set_test_params(self): def run_test (self): # Make sure wallet is really disabled - assert_raises_rpc_error(-32601, 'Method not found', self.nodes[0].getwalletinfo) + assert_raises_rpc_error(-32601, 'Method not found: getwalletinfo', self.nodes[0].getwalletinfo) x = self.nodes[0].validateaddress('3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy') assert(x['isvalid'] == False) x = self.nodes[0].validateaddress('xwMWGTnBNUmGxMm8vfAdbL45bWXyVTYctd')