From 82fc4017b774aaff8799c2b6e8ba5370d94dbf4d Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 30 Jul 2020 18:43:45 -0700 Subject: [PATCH] test: Catch decimal.InvalidOperation from TestNodeCLI#send_cli decimal.InvalidOperation is a special case of a float parsing error, which presumably should be handled in the same way as a general parsing error, rather than blow up. Alternatives include: logging the error, or re-raising with more information. Example log output: File "/home/travis/build/bitcoin/bitcoin/ci/scratch/build/bitcoin-i686-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 603, in sync_all self.sync_blocks(nodes) File "/home/travis/build/bitcoin/bitcoin/ci/scratch/build/bitcoin-i686-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 568, in sync_blocks best_hash = [x.getbestblockhash() for x in rpc_connections] File "/home/travis/build/bitcoin/bitcoin/ci/scratch/build/bitcoin-i686-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 568, in best_hash = [x.getbestblockhash() for x in rpc_connections] File "/home/travis/build/bitcoin/bitcoin/ci/scratch/build/bitcoin-i686-pc-linux-gnu/test/functional/test_framework/test_node.py", line 571, in __call__ return self.cli.send_cli(self.command, *args, **kwargs) File "/home/travis/build/bitcoin/bitcoin/ci/scratch/build/bitcoin-i686-pc-linux-gnu/test/functional/test_framework/test_node.py", line 639, in send_cli return json.loads(cli_stdout, parse_float=decimal.Decimal) File "/usr/lib64/python3.6/json/__init__.py", line 367, in loads return cls(**kw).decode(s) File "/usr/lib64/python3.6/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib64/python3.6/json/decoder.py", line 355, in raw_decode obj, end = self.scan_once(s, idx) decimal.InvalidOperation: [] --- test/functional/test_framework/test_node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 66bb2c89b5..a5abe77870 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -637,7 +637,7 @@ class TestNodeCLI(): raise subprocess.CalledProcessError(returncode, self.binary, output=cli_stderr) try: return json.loads(cli_stdout, parse_float=decimal.Decimal) - except json.JSONDecodeError: + except (json.JSONDecodeError, decimal.InvalidOperation): return cli_stdout.rstrip("\n") class RPCOverloadWrapper():