Skip to content

Commit 17db84d

Browse files
committed
Merge bitcoin/bitcoin#31251: test: report detailed msg during utf8 response decoding error
a2c45ae test: report failure during utf8 response decoding (furszy) Pull request description: Useful for debugging issues such bitcoin/bitcoin#31241 (comment). Prints the entire response content instead of printing only the position of the byte it can't be decoded. The diff between the error messages can be seen by running the `wallet_migration.py` functional test with the following patch applied: ``` diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp --- a/src/wallet/rpc/wallet.cpp(revision d65918c5da52c7d5035b4151dee9ffb2e94d4761) +++ b/src/wallet/rpc/wallet.cpp(date 1731005254673) @@ -801,7 +801,7 @@ } UniValue r{UniValue::VOBJ}; - r.pushKV("wallet_name", res->wallet_name); + r.pushKV("wallet_name", "\xc3\x28"); if (res->watchonly_wallet) { r.pushKV("watchonly_name", res->watchonly_wallet->GetName()); } ``` ACKs for top commit: achow101: ACK a2c45ae theStack: re-ACK a2c45ae rkrux: tACK a2c45ae ismaelsadeeq: utACK a2c45ae Tree-SHA512: 6abb524b5a215c51ec881eea91ebe8174140a88ff3874c8c88676157edae7818801356586a904dbb21b45053183315a6d71dbf917d753611d8e413776b57c484
2 parents e6f1424 + a2c45ae commit 17db84d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

test/functional/test_framework/authproxy.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,12 @@ def _get_response(self):
188188
{'code': -342, 'message': 'non-JSON HTTP response with \'%i %s\' from server' % (http_response.status, http_response.reason)},
189189
http_response.status)
190190

191-
responsedata = http_response.read().decode('utf8')
191+
data = http_response.read()
192+
try:
193+
responsedata = data.decode('utf8')
194+
except UnicodeDecodeError as e:
195+
raise JSONRPCException({
196+
'code': -342, 'message': f'Cannot decode response in utf8 format, content: {data}, exception: {e}'})
192197
response = json.loads(responsedata, parse_float=decimal.Decimal)
193198
elapsed = time.time() - req_start_time
194199
if "error" in response and response["error"] is None:

0 commit comments

Comments
 (0)