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.