test: restore JSONRPCException error format
What changed, and why it matters
This is a test-only code change that restores the string format of an error message shown when a Bitcoin Core functional test encounters a JSON-RPC failure. It only affects test framework output formatting and has no bearing on the live Bitcoin Core software or its users' funds or network security.
No security action needed. This is a benign test-framework regression fix. Reviewers may optionally verify that the restored format matches expectations in dependent tests.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies test/functional/test_framework/util.py’s JSONRPCException class. It changes the exception’s str representation back to a format that includes the RPC error message, code, any extra fields, and HTTP status, while keeping the original rpc_error dict available as self.error. It also imports copy and uses a shallow copy to avoid mutating the original error dict when popping required keys. The stated purpose is to fix test_node.py’s handling of the exception, which checks error[‘code’].
Changed components
test/functional/test_framework/util.pyInspect captured patch +8 / −1
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index ee8061fd..7d064d68 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -5,6 +5,7 @@
"""Helpful routines for regression testing."""
from base64 import b64encode
+from copy import copy
from decimal import Decimal
from subprocess import CalledProcessError
import hashlib
@@ -30,10 +31,16 @@ logger = logging.getLogger("TestFramework.utils")
class JSONRPCException(Exception):
def __init__(self, rpc_error, http_status=None):
- super().__init__(f"{rpc_error} [http_status={http_status}]")
self.error = rpc_error
self.http_status = http_status
+ # throw KeyError if any required fields are missing
+ copied_error = copy(rpc_error)
+ message = copied_error.pop("message")
+ code = copied_error.pop("code")
+ extra = f'{copied_error}' if copied_error else ''
+ super().__init__(f"{message} ({code}) {extra} [http_status={http_status}]")
+
# Assert functions
##################
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.