mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 23:03:45 +01:00
Merge bitcoin/bitcoin#25737: rpc: treat univalue type check error as RPC_TYPE_ERROR, not RPC_MISC_ERROR
e68d380797rpc: remove unneeded RPCTypeCheckArgument checks (furszy)55566630c6rpc: treat univalue type check error as RPC_TYPE_ERROR, not RPC_MISC_ERROR (furszy) Pull request description: Same rationale as #26039, tackling another angle of the problem. #### Context We have the same univalue type error checking code spread/duplicated few times: `RPCTypeCheckObj`, `RPCTypeCheckArgument`, `UniValue::checkType`. In the first two functions, we are properly returning an `RPC_TYPE_ERROR` while in `UniValue::checkType` we are throwing an `std::runtime_error` which is caught by the RPC server request handler, who invalidly treats it as `RPC_MISC_ERROR` (which is a generic error return code that provides no information to the user). #### Proposed Changes Throw a custom exception from `Univalue::checkType` (instead of a plain `std::runtime_error`) and catch it on the RPC server request handler. So we properly return `RPC_TYPE_ERROR` (-3) on every arg type error and not the general `RPC_MISC_ERROR` (-1). This will allow us to remove all the `RPCTypeCheckArgument` calls. As them are redundant since #25629. Top commit has no ACKs. Tree-SHA512: 4e4c41851fd4e2b01a2d8b94e71513f9831f810768ebd89684caca4901e87d3677980003949bcce441f9ca607a1b38a5894839b6c492f5947b8bab8cd9423ba6
This commit is contained in:
@@ -466,8 +466,7 @@ UniValue CRPCTable::execute(const JSONRPCRequest &request) const
|
||||
|
||||
static bool ExecuteCommand(const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler)
|
||||
{
|
||||
try
|
||||
{
|
||||
try {
|
||||
RPCCommandExecution execution(request.strMethod);
|
||||
// Execute, convert arguments to array if necessary
|
||||
if (request.params.isObject()) {
|
||||
@@ -475,9 +474,9 @@ static bool ExecuteCommand(const CRPCCommand& command, const JSONRPCRequest& req
|
||||
} else {
|
||||
return command.actor(request, result, last_handler);
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
} catch (const UniValue::type_error& e) {
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, e.what());
|
||||
} catch (const std::exception& e) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user