Browse Source

tests: Add exception error message for JSONRPCException

This improves error reporting if `JSONRPCException` is not specifically caught
and ends up in Python's default backtrace handler.

Before:
```
Traceback (most recent call last):
  File "/.../projects/bitcoin/bitcoin/qa/rpc-tests/test_framework/authproxy.py", line 153, in __call__
    raise JSONRPCException(response['error'])
test_framework.authproxy.JSONRPCException
```

After:
```
Traceback (most recent call last):
  File "/.../projects/bitcoin/bitcoin/qa/rpc-tests/test_framework/authproxy.py", line 152, in __call__
    raise JSONRPCException(response['error'])
test_framework.authproxy.JSONRPCException: Unknown named parameter random (-8)
```
0.14
Wladimir J. van der Laan 8 years ago
parent
commit
42f6aed731
  1. 6
      qa/rpc-tests/test_framework/authproxy.py

6
qa/rpc-tests/test_framework/authproxy.py

@ -55,7 +55,11 @@ log = logging.getLogger("BitcoinRPC")
class JSONRPCException(Exception): class JSONRPCException(Exception):
def __init__(self, rpc_error): def __init__(self, rpc_error):
Exception.__init__(self) try:
errmsg = '%(message)s (%(code)i)' % rpc_error
except (KeyError, TypeError):
errmsg = ''
Exception.__init__(self, errmsg)
self.error = rpc_error self.error = rpc_error

Loading…
Cancel
Save