rpc: Use type-safe exception to pass RPC help

This commit is contained in:
MarcoFalke committed 2025-06-12 11:36:43 +02:00
1 parent 5757de4ddd
commit eeeec1579e
3 files changed
+7 -6

No files matched your search

+2 -5
View File
@@ -97,11 +97,8 @@ std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest&
UniValue unused_result; UniValue unused_result;
if (setDone.insert(pcmd->unique_id).second) if (setDone.insert(pcmd->unique_id).second)
pcmd->actor(jreq, unused_result, /*last_handler=*/true); pcmd->actor(jreq, unused_result, /*last_handler=*/true);
} } catch (const HelpResult& e) {
catch (const std::exception& e) std::string strHelp{e.what()};
{
// Help text is returned in an exception
std::string strHelp = std::string(e.what());
if (strCommand == "") if (strCommand == "")
{ {
if (strHelp.find('\n') != std::string::npos) if (strHelp.find('\n') != std::string::npos)
+1 -1
View File
@@ -645,7 +645,7 @@ UniValue RPCHelpMan::HandleRequest(const JSONRPCRequest& request) const
* the user is asking for help information, and throw help when appropriate. * the user is asking for help information, and throw help when appropriate.
*/ */
if (request.mode == JSONRPCRequest::GET_HELP || !IsValidNumArgs(request.params.size())) { if (request.mode == JSONRPCRequest::GET_HELP || !IsValidNumArgs(request.params.size())) {
throw std::runtime_error(ToString()); throw HelpResult{ToString()};
} }
UniValue arg_mismatch{UniValue::VOBJ}; UniValue arg_mismatch{UniValue::VOBJ};
for (size_t i{0}; i < m_args.size(); ++i) { for (size_t i{0}; i < m_args.size(); ++i) {
+4
View File
@@ -67,6 +67,10 @@ class FillableSigningProvider;
class CScript; class CScript;
struct Sections; struct Sections;
struct HelpResult : std::runtime_error {
explicit HelpResult(const std::string& msg) : std::runtime_error{msg} {}
};
/** /**
* Gets all existing output types formatted for RPC help sections. * Gets all existing output types formatted for RPC help sections.
* *