test: Catch decimal.InvalidOperation from TestNodeCLI#send_cli #19632

pull Empact wants to merge 1 commits into bitcoin:master from Empact:2020-07-send_cli-invalid-op changing 1 files +1 −1
  1. Empact commented at 1:49 AM on July 31, 2020: member

    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 <listcomp>
          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: [<class 'decimal.InvalidOperation'>]
    

    See: https://travis-ci.org/github/bitcoin/bitcoin/jobs/713502326

  2. 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 <listcomp>
          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: [<class 'decimal.InvalidOperation'>]
    82fc4017b7
  3. fanquake added the label Tests on Jul 31, 2020
  4. MarcoFalke commented at 4:41 AM on July 31, 2020: member

    Too bad the stdout isn't available. I presume it is something like "connection reset"?

    ACK

  5. laanwj commented at 2:13 PM on August 5, 2020: member

    ACK 82fc4017b774aaff8799c2b6e8ba5370d94dbf4d

    I don't understand what happened though. If you psas invalid input to a Decimal, you'll normally get this message:

    >>> decimal.Decimal("sdfsdf3f")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
    

    The exception message has a condition "decimal.ConversionSyntax". However in your case, the condition isdecimal.InvalidOperation itself. Too bad we can't see the input.

  6. MarcoFalke commented at 2:27 PM on August 5, 2020: member

    Looks like this might happen when the quantization is too precise:

    >>> decimal.Decimal(3).quantize(decimal.Decimal('0.000000000000000000000000000000000000000000001'), rounding=decimal.ROUND_DOWN)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]
    

    or

    >>> decimal.Decimal('inf')*0
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]
    

    See https://docs.python.org/3.8/library/decimal.html#decimal.InvalidOperation

    Though, still no idea how that could happen in our test framework.

  7. laanwj merged this on Aug 5, 2020
  8. laanwj closed this on Aug 5, 2020

  9. laanwj commented at 2:47 PM on August 5, 2020: member

    It looks like it also happens if some limit is exceeded e.g. decimal.Decimal("1e9999999999999999999") (wasn't able to trigger this with just a long number without exponent). This would be possible to trigger though unlikely.

  10. Empact deleted the branch on Aug 5, 2020
  11. sidhujag referenced this in commit a4ebad2aa2 on Aug 5, 2020
  12. jasonbcox referenced this in commit 7cfda4b280 on Sep 3, 2020
  13. PastaPastaPasta referenced this in commit e4db0a06eb on Sep 17, 2021
  14. PastaPastaPasta referenced this in commit 72f2882efe on Sep 19, 2021
  15. thelazier referenced this in commit ccc2fbfb4a on Sep 25, 2021
  16. DrahtBot locked this on Feb 15, 2022
Labels

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-30 00:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me