Merge bitcoin/bitcoin#34575: test: Avoid empty errmsg in JSONRPCException

211111b804 test: Avoid empty errmsg in JSONRPCException (MarcoFalke)

Pull request description:

  It is unclear why the fallback should be an empty message, when it is better to include all rpc_error details that are available.

  Also, include the http status.

  This allows to revert commit 6354b4fd7f, because it is no longer needed.

  Can be tested by running this diff:

  ```diff
  diff --git a/test/functional/wallet_disable.py b/test/functional/wallet_disable.py
  index dbcccd4778..9717a2d248 100755
  --- a/test/functional/wallet_disable.py
  +++ b/test/functional/wallet_disable.py
  @@ -18,9 +18,8 @@ class DisableWalletTest (BitcoinTestFramework):
           self.extra_args = [["-disablewallet"]]
           self.wallet_names = []

  -    def run_test (self):
  -        # Make sure wallet is really disabled
  -        assert_raises_rpc_error(-32601, 'Method not found', self.nodes[0].getwalletinfo)
  +    def run_test(self):
  +        self.nodes[0].getwalletinfo()
           x = self.nodes[0].validateaddress('3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy')
           assert x['isvalid'] == False
           x = self.nodes[0].validateaddress('mneYUmWYsuk7kySiURxCi3AGxrAqZxLgPZ')

ACKs for top commit:
  ismaelsadeeq:
    utACK 211111b804
  furszy:
    utACK 211111b804
  hodlinator:
    ACK 211111b804
  rkrux:
    tACK 211111b804

Tree-SHA512: 92067aaaa61a887398e38f587004ba31070acc6a9dbd003e9e35393e8c049e786177afa43da05d2d653af340b6c69803c4323061d73d417219bcdf37729e4b66
This commit is contained in:
merge-script
2026-02-17 09:40:06 +00:00
2 changed files with 4 additions and 9 deletions

View File

@@ -51,11 +51,7 @@ log = logging.getLogger("BitcoinRPC")
class JSONRPCException(Exception):
def __init__(self, rpc_error, http_status=None):
try:
errmsg = '%(message)s (%(code)i)' % rpc_error
except (KeyError, TypeError):
errmsg = ''
super().__init__(errmsg)
super().__init__(f"{rpc_error} [http_status={http_status}]")
self.error = rpc_error
self.http_status = http_status

View File

@@ -147,11 +147,10 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
except subprocess.CalledProcessError as e:
self.log.exception(f"Called Process failed with stdout='{e.stdout}'; stderr='{e.stderr}';")
self.success = TestStatus.FAILED
except JSONRPCException as e:
self.log.exception(f"Failure during setup: error={e.error}, http_status={e.http_status}")
self.success = TestStatus.FAILED
except BaseException:
self.log.exception("Unexpected exception")
# The `exception` log will add the exception info to the message.
# https://docs.python.org/3/library/logging.html#logging.exception
self.log.exception("Unexpected exception:")
self.success = TestStatus.FAILED
finally:
exit_code = self.shutdown()