Skip to content

Commit eeeec15

Browse files
author
MarcoFalke
committed
rpc: Use type-safe exception to pass RPC help
1 parent 5757de4 commit eeeec15

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/rpc/server.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,8 @@ std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest&
9797
UniValue unused_result;
9898
if (setDone.insert(pcmd->unique_id).second)
9999
pcmd->actor(jreq, unused_result, /*last_handler=*/true);
100-
}
101-
catch (const std::exception& e)
102-
{
103-
// Help text is returned in an exception
104-
std::string strHelp = std::string(e.what());
100+
} catch (const HelpResult& e) {
101+
std::string strHelp{e.what()};
105102
if (strCommand == "")
106103
{
107104
if (strHelp.find('\n') != std::string::npos)

src/rpc/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ UniValue RPCHelpMan::HandleRequest(const JSONRPCRequest& request) const
645645
* the user is asking for help information, and throw help when appropriate.
646646
*/
647647
if (request.mode == JSONRPCRequest::GET_HELP || !IsValidNumArgs(request.params.size())) {
648-
throw std::runtime_error(ToString());
648+
throw HelpResult{ToString()};
649649
}
650650
UniValue arg_mismatch{UniValue::VOBJ};
651651
for (size_t i{0}; i < m_args.size(); ++i) {

src/rpc/util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class FillableSigningProvider;
6767
class CScript;
6868
struct Sections;
6969

70+
struct HelpResult : std::runtime_error {
71+
explicit HelpResult(const std::string& msg) : std::runtime_error{msg} {}
72+
};
73+
7074
/**
7175
* Gets all existing output types formatted for RPC help sections.
7276
*

0 commit comments

Comments
 (0)