-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Fix misleading "Method not found" multiwallet errors #10931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Raise RPC_WALLET_NOT_SPECIFIED instead of RPC_METHOD_NOT_FOUND when a required wallet filename was not specified in an RPC call. Also raise more specific RPC_WALLET_NOT_FOUND error instead of RPC_INVALID_PARAMETER in case an invalid wallet was specified, for consistency.
Should tag for 0.15 since this fixes a new error and wouldn't be backwards compatible if it was in a later release. |
utACK 5bb4fe6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definite concept ACK, and agree that this should go into v0.15 as a bugfix.
I'll test tomorrow.
src/wallet/rpcwallet.cpp
Outdated
if (avoidException) return false; | ||
if (::vpwallets.empty()) { | ||
// Wallet RPC methods are disabled if no wallets are loaded. | ||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance of changing the error message to Method not found (wallet disabled)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or "no wallets loaded", I think that's more relevant now, especially when runtime loading/unloading is added later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread #10931 (comment)
Ok, added in 4cfa444
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it appears that it's not currently possible to hit this error. If bitcoind is started with disablewallet
then the wallet RPC commands aren't registered and any call to a wallet RPC will be rejected here:
Line 495 in 5c8eb79
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found"); |
Code looks good and will be required when dynamic wallet loading is implemented, but is not currently testable. Suggest you leave the code in, but add a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread #10931 (comment)
Interesting, added comment in 0ed0352.
src/wallet/rpcwallet.cpp
Outdated
// Wallet RPC methods are disabled if no wallets are loaded. | ||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)"); | ||
} | ||
throw JSONRPCError(RPC_WALLET_NOT_SPECIFIED, "Wallet file not specified (please provide bitcoin-cli " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we should mention a specific RPC client (bitcoin-cli) on the server side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @jonasschnelli, we shouldn't mention bitcoin-cli in server errors.
Nothing prevents you from catching this specific error code in the client and giving a specific error though, if you want to be user-friendly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread #10931 (comment)
Unclear why this would be an improvement, and how the server mentioning a bitcoin-cli option is different than server providing bitcoin-cli command lines in the help text of all rpc methods (which seems like a good thing to me). Generating the text in one place instead of two places means it can be more coherent. And maybe there is some maintainability argument on the side of having more ambiguous or fragmented text, but in this case adding code to bitcoin-cli to handle wallet not specified doesn't seem like a clear win for maintainability, either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I almost wrote the same comment as Jonas about server not having bitcoin-cli specific messages, but Russ has convinced me. I think it's ok to have a bitcoin-cli message here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NACK. I still disagree. People use RPC from many other programs than just bitcoin-cli. Mentioning a -cli argument is just confusing. If you want to add documentation in an error message, you should document how people should change their API usage instead.
how the server mentioning a bitcoin-cli option is different than server providing bitcoin-cli command lines in the help text of all rpc methods
That's IMO different because it's a clearly isolated context that mentions use of bitcoin-cli, not a random error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread continues here: #10931 (comment)
utACK 5bb4fe6 |
Not strictly backwards compatible because the error is not new in this release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a commit 5bb4fe6 -> 4cfa444 (pr/multierr.1 -> pr/multierr.2, compare)
src/wallet/rpcwallet.cpp
Outdated
// Wallet RPC methods are disabled if no wallets are loaded. | ||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)"); | ||
} | ||
throw JSONRPCError(RPC_WALLET_NOT_SPECIFIED, "Wallet file not specified (please provide bitcoin-cli " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread #10931 (comment)
Unclear why this would be an improvement, and how the server mentioning a bitcoin-cli option is different than server providing bitcoin-cli command lines in the help text of all rpc methods (which seems like a good thing to me). Generating the text in one place instead of two places means it can be more coherent. And maybe there is some maintainability argument on the side of having more ambiguous or fragmented text, but in this case adding code to bitcoin-cli to handle wallet not specified doesn't seem like a clear win for maintainability, either.
src/wallet/rpcwallet.cpp
Outdated
if (avoidException) return false; | ||
if (::vpwallets.empty()) { | ||
// Wallet RPC methods are disabled if no wallets are loaded. | ||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread #10931 (comment)
Ok, added in 4cfa444
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
utACK 4cfa444 |
Tested ACK 4cfa444 |
src/wallet/rpcwallet.cpp
Outdated
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 (please provide bitcoin-cli " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow this got hidden: #10931 (comment)
I still disagree with mentioning -cli here. If there is to be extenxsive documentation here, this should mention how to change the API usage, as people will be using this API from many applications and not just bitcoin-cli.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @laanwj. Please remove the bitcoin-cli
part.
By design, it makes no sense to report client specific error message in a pure JSON RPC server implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread #10931 (comment)
Ok @laanwj, thanks for providing an explanation. I implemented your suggestion in 6b5c343. I think we're basically talking about a tradeoff between more useful vs more maintainable help text, though differences ares very small in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a way, yes, though I don't think this is much less maintainable; we have those error codes for a reason, might as well use them to print custom text at the client side. We could at some point provide a better help text for other codes as well, where it makes sense. Anoher advantage of generating messages at the client side is that they could be translated (though we currently don't support translation in any way in non-qt).
In any case thanks for implementing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added 2 commits 4cfa444 -> 6b5c343 (pr/multierr.2 -> pr/multierr.3, compare)
Squashed 6b5c343 -> df389bc (pr/multierr.3 -> pr/multierr.4)
src/wallet/rpcwallet.cpp
Outdated
if (avoidException) return false; | ||
if (::vpwallets.empty()) { | ||
// Wallet RPC methods are disabled if no wallets are loaded. | ||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread #10931 (comment)
Interesting, added comment in 0ed0352.
src/wallet/rpcwallet.cpp
Outdated
// Wallet RPC methods are disabled if no wallets are loaded. | ||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)"); | ||
} | ||
throw JSONRPCError(RPC_WALLET_NOT_SPECIFIED, "Wallet file not specified (please provide bitcoin-cli " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread continues here: #10931 (comment)
src/wallet/rpcwallet.cpp
Outdated
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 (please provide bitcoin-cli " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread #10931 (comment)
Ok @laanwj, thanks for providing an explanation. I implemented your suggestion in 6b5c343. I think we're basically talking about a tradeoff between more useful vs more maintainable help text, though differences ares very small in this case.
utACK df389bc |
df389bc Change wallet method disabled error text (Russell Yanofsky) e526b3d Fix misleading "Method not found" multiwallet errors (Russell Yanofsky) Pull request description: Raise RPC_WALLET_NOT_SPECIFIED instead of RPC_METHOD_NOT_FOUND when a required wallet filename was not specified in an RPC call. Also raise more specific RPC_WALLET_NOT_FOUND error instead of RPC_INVALID_PARAMETER in case an invalid wallet was specified, for consistency. Tree-SHA512: 6a8d885283f69bcfc28f2e08ac03eff02f9f8160a312ce2a90d868aa52533434fc0b4c4ab86547c2f09392338956df915637eaf7136a4fc105e6c8179f2d0ac8
…rors df389bc Change wallet method disabled error text (Russell Yanofsky) e526b3d Fix misleading "Method not found" multiwallet errors (Russell Yanofsky) Pull request description: Raise RPC_WALLET_NOT_SPECIFIED instead of RPC_METHOD_NOT_FOUND when a required wallet filename was not specified in an RPC call. Also raise more specific RPC_WALLET_NOT_FOUND error instead of RPC_INVALID_PARAMETER in case an invalid wallet was specified, for consistency. Tree-SHA512: 6a8d885283f69bcfc28f2e08ac03eff02f9f8160a312ce2a90d868aa52533434fc0b4c4ab86547c2f09392338956df915637eaf7136a4fc105e6c8179f2d0ac8
…rors df389bc Change wallet method disabled error text (Russell Yanofsky) e526b3d Fix misleading "Method not found" multiwallet errors (Russell Yanofsky) Pull request description: Raise RPC_WALLET_NOT_SPECIFIED instead of RPC_METHOD_NOT_FOUND when a required wallet filename was not specified in an RPC call. Also raise more specific RPC_WALLET_NOT_FOUND error instead of RPC_INVALID_PARAMETER in case an invalid wallet was specified, for consistency. Tree-SHA512: 6a8d885283f69bcfc28f2e08ac03eff02f9f8160a312ce2a90d868aa52533434fc0b4c4ab86547c2f09392338956df915637eaf7136a4fc105e6c8179f2d0ac8
…rors df389bc Change wallet method disabled error text (Russell Yanofsky) e526b3d Fix misleading "Method not found" multiwallet errors (Russell Yanofsky) Pull request description: Raise RPC_WALLET_NOT_SPECIFIED instead of RPC_METHOD_NOT_FOUND when a required wallet filename was not specified in an RPC call. Also raise more specific RPC_WALLET_NOT_FOUND error instead of RPC_INVALID_PARAMETER in case an invalid wallet was specified, for consistency. Tree-SHA512: 6a8d885283f69bcfc28f2e08ac03eff02f9f8160a312ce2a90d868aa52533434fc0b4c4ab86547c2f09392338956df915637eaf7136a4fc105e6c8179f2d0ac8
…rors df389bc Change wallet method disabled error text (Russell Yanofsky) e526b3d Fix misleading "Method not found" multiwallet errors (Russell Yanofsky) Pull request description: Raise RPC_WALLET_NOT_SPECIFIED instead of RPC_METHOD_NOT_FOUND when a required wallet filename was not specified in an RPC call. Also raise more specific RPC_WALLET_NOT_FOUND error instead of RPC_INVALID_PARAMETER in case an invalid wallet was specified, for consistency. Tree-SHA512: 6a8d885283f69bcfc28f2e08ac03eff02f9f8160a312ce2a90d868aa52533434fc0b4c4ab86547c2f09392338956df915637eaf7136a4fc105e6c8179f2d0ac8
…rors df389bc Change wallet method disabled error text (Russell Yanofsky) e526b3d Fix misleading "Method not found" multiwallet errors (Russell Yanofsky) Pull request description: Raise RPC_WALLET_NOT_SPECIFIED instead of RPC_METHOD_NOT_FOUND when a required wallet filename was not specified in an RPC call. Also raise more specific RPC_WALLET_NOT_FOUND error instead of RPC_INVALID_PARAMETER in case an invalid wallet was specified, for consistency. Tree-SHA512: 6a8d885283f69bcfc28f2e08ac03eff02f9f8160a312ce2a90d868aa52533434fc0b4c4ab86547c2f09392338956df915637eaf7136a4fc105e6c8179f2d0ac8
…rors df389bc Change wallet method disabled error text (Russell Yanofsky) e526b3d Fix misleading "Method not found" multiwallet errors (Russell Yanofsky) Pull request description: Raise RPC_WALLET_NOT_SPECIFIED instead of RPC_METHOD_NOT_FOUND when a required wallet filename was not specified in an RPC call. Also raise more specific RPC_WALLET_NOT_FOUND error instead of RPC_INVALID_PARAMETER in case an invalid wallet was specified, for consistency. Tree-SHA512: 6a8d885283f69bcfc28f2e08ac03eff02f9f8160a312ce2a90d868aa52533434fc0b4c4ab86547c2f09392338956df915637eaf7136a4fc105e6c8179f2d0ac8
…rors df389bc Change wallet method disabled error text (Russell Yanofsky) e526b3d Fix misleading "Method not found" multiwallet errors (Russell Yanofsky) Pull request description: Raise RPC_WALLET_NOT_SPECIFIED instead of RPC_METHOD_NOT_FOUND when a required wallet filename was not specified in an RPC call. Also raise more specific RPC_WALLET_NOT_FOUND error instead of RPC_INVALID_PARAMETER in case an invalid wallet was specified, for consistency. Tree-SHA512: 6a8d885283f69bcfc28f2e08ac03eff02f9f8160a312ce2a90d868aa52533434fc0b4c4ab86547c2f09392338956df915637eaf7136a4fc105e6c8179f2d0ac8
d5526bd Wrap dumpwallet warning and note scripts aren't dumped (MeshCollider) 3711c6a Add wallet backup text to import*, add* and dumpwallet RPCs (MeshCollider) dbda874 [Wallet] always show help-line of wallet encryption calls (Jonas Schnelli) 20c269b Avoid opening copied wallet databases simultaneously (Russell Yanofsky) e411b70 [wallet] Fix leak in CDB constructor (João Barbosa) f15aeea Change getmininginfo errors field to warnings (Andrew Chow) c04390b Unify help text for GetWarnings output in get*info RPCs (random-zebra) 1d966ce Add warnings field to getblockchaininfo (Andrew Chow) ffcd781 [Trivial] Cleanup after MOVE-ONLY commits (random-zebra) e067235 MOVEONLY: Init functions wallet/wallet.cpp -> wallet/init.cpp (random-zebra) e947eec MOVEONLY: Fee functions wallet/wallet.cpp -> wallet/fees.cpp (random-zebra) 2188c3e Move some static functions out of wallet.h/cpp (random-zebra) f49acf7 [wallet] [moveonly] Move CAffectedKeysVisitor (random-zebra) 8bd979f [wallet] Specify wallet name in wallet loading errors (random-zebra) 900bbfa Reject invalid wallet files (João Barbosa) a1f4e2a Reject duplicate wallet filenames (random-zebra) ee52c2e Fix misleading "Method not found" multiwallet errors (Russell Yanofsky) ce35e1e [Qt] Use wallet 0 in rpc console if running with multiple wallets (random-zebra) 37089d1 [tests] Update wallet_multiwallet.py functional test (random-zebra) 3955ee9 [Doc] Update release notes (random-zebra) 4fd5913 [wallet] [rpc] Add listwallets RPC (John Newbery) 1525281 [wallet] [rpc] print wallet name in getwalletinfo (John Newbery) fdf5da0 [wallet] fix comment for CWallet::Verify() (John Newbery) cf4a90b Remove factor of 3 from definition of dust. (random-zebra) a1c56fd [Policy] Introduce -dustrelayfee (random-zebra) 9fb29cc [Doc] Update multiwallet release notes (random-zebra) 379255e [Tests][Trivial] Add wallet_multiwallet.py to test_runner (random-zebra) 808fbc3 [Bugfix] consider boolean value of -zapwallettxes ParameterInteraction (random-zebra) f9141f8 [QA] Add wallet_multiwallet.py functional test (John Newbery) 2e02006 Rename -usewallet to -rpcwallet (Alex Morcos) a64440b Select wallet based on the given endpoint (Jonas Schnelli) 5683a9c Complete previous commit by moving mn stuff out of libbitcoin_wallet (random-zebra) b0fe92f Fix test_pivx circular dependency issue (random-zebra) 6cb2b92 Add wallet endpoint support to bitcoin-cli (-usewallet) (Jonas Schnelli) 7dd3916 Register wallet endpoint (Jonas Schnelli) 5bd1bd7 Properly forbid -salvagewallet and -zapwallettxes for multi wallet. (Alex Morcos) 41a7335 Remove unused variables (practicalswift) 5c3d73f Avoid CWalletTx copies in GetAddressBalances and GetAddressGroupings (Russell Yanofsky) e7cafab [Refactoring] Mimic ListCoins for sapling notes (random-zebra) 54fa122 [qt] Move some WalletModel functions into CWallet (random-zebra) 494ba64 [test] Add test for getmemoryinfo (random-zebra) 2394083 [Wallet] unset change position when there is no change on exact match (Gregory Sanders) 7d977ac Remove unused C++ code not covered by unit tests (random-zebra) 60bb4da ApproximateBestSubset should take inputs by reference, not value (Ryan Havar) 3633d75 Initialize nRelockTime (Patrick Strateman) 3a599d0 [Refactor] Return safeTx boolean in CheckTXAvailability (random-zebra) f219be9 Add safe flag to listunspent result (NicolasDorier) 0201065 Add COutput::fSafe member for safe handling of unconfirmed outputs (random-zebra) 75c8c6d Disallow copy of CReserveKeys (Gregory Sanders) 8378322 [Refactor] Replace optional reserveKey in PBF with unique pointer (random-zebra) Pull request description: I think these are all the remaining Bitcoin Core v0.15 PRs in the wallet area that we don't have yet, and are useful to us. I've grouped them here since they are all pretty small, simple, and narrow-focused (on the wallet/rpcwallet files). This changeset is based on top of - [x] #2337 as it keeps going with the multiwallet implementation, adding: - RPC endpoint support - `listwallets` RPC - wallet name in `getwalletinfo` RPC - `wallet_multiwallet.py` functional test As in some areas we are much closer to upstream, some of the commits needed adaptations (especially the functional tests). A couple of commits have been extended to include shield-related code. List of upstream PRs backported/adapted: - bitcoin#9906 : Disallow copy constructor CReserveKeys - bitcoin#9830 : Add safe flag to listunspent result - bitcoin#9993 : Initialize nRelockTime - bitcoin#10108 : ApproximateBestSubset should take inputs by reference, not value - bitcoin#10075 : Remove unused C++ code not covered by unit tests - bitcoin#10257 : Add test for getmemoryinfo - bitcoin#10295 : Move some WalletModel functions into CWallet - bitcoin#10500 : Avoid CWalletTx copies in GetAddressBalances and GetAddressGroupings - bitcoin#10522 : Remove unused variables - bitcoin#10816 : Properly forbid -salvagewallet and -zapwallettxes for multi wallet - bitcoin#10849 : Multiwallet: simplest endpoint support - bitcoin#9380 : Separate different uses of minimum fees (only dustRelayFee) - bitcoin#10817 : Redefine Dust and add a discard_rate (only first commit) - bitcoin#10883 : Rename -usewallet to -rpcwallet - bitcoin#10604 : Add listwallets RPC, include wallet name in getwalletinfo + tests - bitcoin#10893 : Avoid running multiwallet.py twice - bitcoin#10870 : Use wallet 0 in rpc console if running with multiple wallets - bitcoin#10931 : Fix misleading "method not found" multiwallet errors - bitcoin#10885 : Reject invalid wallets - bitcoin#11022 : Basic keypool topup - bitcoin#10976 : [MOVEONLY] Move some static functions out of wallet.h/cpp - bitcoin#11310 : Test listwallets RPC - bitcoin#10858 : "errors" to getblockchaininfo + unify "errors" field in get*info RPCs - bitcoin#11492 : Fix leak in CDB constructor - bitcoin#11476 : Avoid opening copied wallet databases simultaneously - bitcoin#11590 : always show help-line of wallet encryption calls - bitcoin#11289 : Add wallet backup text to import* and add* RPCs ACKs for top commit: furszy: re-re-utACK d5526bd. Fuzzbawls: ACK d5526bd Tree-SHA512: 115c4916ee212539b0a1b2cb25783ddf6753f5376de739a084191e874ed8717fff2c7cd9d744e397891f14eaa459ef2f48d675168621ef7316e81758fa6559f2
Raise RPC_WALLET_NOT_SPECIFIED instead of RPC_METHOD_NOT_FOUND when a required
wallet filename was not specified in an RPC call.
Also raise more specific RPC_WALLET_NOT_FOUND error instead of
RPC_INVALID_PARAMETER in case an invalid wallet was specified, for consistency.