From ac09260982acbe1e9cdfb78eae289bbaf335f3e4 Mon Sep 17 00:00:00 2001 From: rkrux Date: Tue, 26 May 2026 20:14:47 +0530 Subject: [PATCH] test: restore JSONRPCException error format This is a follow-up to PR 34575. Copy is done so that checking of error["code"] in test_node.py while handling this exception doesn't fail. Co-authored-by: maflcko <6399679+maflcko@users.noreply.github.com> --- test/functional/test_framework/util.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index ee8061fda09..7d064d68a9f 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 ##################