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 ##################