refactor: Use STR_INTERNAL_BUG macro where possible
What changed, and why it matters
This commit is a code cleanup that replaces several hand-written internal-error messages with a single standard macro. It does not change what the program does, only how error messages are formatted. There is no security issue here.
No security action needed. Treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors three call sites in src/rest.cpp and src/rpc/util.cpp to use the STR_INTERNAL_BUG macro instead of manually constructed strprintf(…) strings that included FILE, LINE, func, CLIENT_NAME, FormatFullVersion(), and CLIENT_BUGREPORT. The macro already produces the same template, so behavior is preserved. Includes for bitcoin-build-config.h and clientversion.h are removed where no longer needed. No functional or security change.
Changed components
src/rest.cppsrc/rpc/util.cppInspect captured patch +5 / −20
diff --git a/src/rest.cpp b/src/rest.cpp
index eb4e52f1..40a07ba1 100644
--- a/src/rest.cpp
+++ b/src/rest.cpp
@@ -1,10 +1,8 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2022 The Bitcoin Core developers
+// Copyright (c) 2009-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include <bitcoin-build-config.h> // IWYU pragma: keep
-
#include <rest.h>
#include <blockfilter.h>
@@ -87,11 +85,7 @@ static NodeContext* GetNodeContext(const std::any& context, HTTPRequest* req)
{
auto node_context = util::AnyPtr<NodeContext>(context);
if (!node_context) {
- RESTERR(req, HTTP_INTERNAL_SERVER_ERROR,
- strprintf("%s:%d (%s)\n"
- "Internal bug detected: Node context not found!\n"
- "You may report this issue here: %s\n",
- __FILE__, __LINE__, __func__, CLIENT_BUGREPORT));
+ RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, STR_INTERNAL_BUG("Node context not found!"));
return nullptr;
}
return node_context;
@@ -125,11 +119,7 @@ static ChainstateManager* GetChainman(const std::any& context, HTTPRequest* req)
{
auto node_context = util::AnyPtr<NodeContext>(context);
if (!node_context || !node_context->chainman) {
- RESTERR(req, HTTP_INTERNAL_SERVER_ERROR,
- strprintf("%s:%d (%s)\n"
- "Internal bug detected: Chainman disabled or instance not found!\n"
- "You may report this issue here: %s\n",
- __FILE__, __LINE__, __func__, CLIENT_BUGREPORT));
+ RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, STR_INTERNAL_BUG("Chainman disabled or instance not found!"));
return nullptr;
}
return node_context->chainman.get();
diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp
index 4813324c..642b8c09 100644
--- a/src/rpc/util.cpp
+++ b/src/rpc/util.cpp
@@ -2,10 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include <bitcoin-build-config.h> // IWYU pragma: keep
-
#include <chain.h>
-#include <clientversion.h>
#include <common/args.h>
#include <common/messages.h>
#include <common/types.h>
@@ -678,10 +675,8 @@ UniValue RPCHelpMan::HandleRequest(const JSONRPCRequest& request) const
mismatch.size() == 1 ? mismatch[0].write(4) :
mismatch.write(4)};
throw std::runtime_error{
- strprintf("Internal bug detected: RPC call \"%s\" returned incorrect type:\n%s\n%s %s\nPlease report this issue here: %s\n",
- m_name, explain,
- CLIENT_NAME, FormatFullVersion(),
- CLIENT_BUGREPORT)};
+ STR_INTERNAL_BUG(strprintf("RPC call \"%s\" returned incorrect type:\n%s", m_name, explain)),
+ };
}
}
return ret;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.