Skip to content

fix: validate --timeout as finite and greater than zero - #587

Closed
LouisDeconinck wants to merge 1 commit into
wavefnd:masterfrom
LouisDeconinck:master
Closed

LouisDeconinck wants to merge 1 commit into
wavefnd:masterfrom
LouisDeconinck:master

Conversation

@LouisDeconinck

Copy link
Copy Markdown

Add validation to reject non-finite and non-positive timeout values
including 0, negative numbers, NaN, and infinities. Use math.isfinite()
to check for finite values and require timeout > 0.

Changes

  • Added timeout validation in parse_args() using math.isfinite()
  • Rejects 0, negative values, NaN, inf, and -inf with clear error messages
  • Created table-driven unit tests in tools/test_check_wave_corpus.py
  • All 9 tests pass, covering edge cases and valid inputs

Test Results

  • Invalid values (0, -1, nan, inf, -inf) now exit with status 2
  • Valid values (default 15.0, 0.25, 30) continue to work
  • Test coverage includes zero, negative, NaN, infinities, non-numeric, default, and positive values

Fixes #585

Add validation to reject non-finite and non-positive timeout values
including 0, negative numbers, NaN, and infinities. Use math.isfinite()
to check for finite values and require timeout > 0.

Add table-driven unit tests covering zero, negative values, NaN, both
infinities, non-numeric input, the default, and positive values.

Fixes wavefnd#585
@LunaStev

Copy link
Copy Markdown
Member

Thanks for the contribution. The behavior implemented here is correct, and I don't see a functional issue with the timeout validation itself.

However, this overlaps with #586, which was opened earlier for the same issue, and I prefer its implementation for a few reasons.

In this PR, validation happens after parser.parse_args():

args = parser.parse_args()

import math
if not math.isfinite(args.timeout) or args.timeout <= 0:
    parser.error(...)

This works, but #586 moves the validation into a dedicated argparse type parser. That keeps parsing and validation together at the CLI boundary and avoids adding validation logic after argument parsing.

#586 also makes parse_args() accept an explicit argv parameter, which makes the argument parser easier to test directly. The tests here instead patch sys.argv for each case.

Additionally, #586 explicitly verifies that an invalid timeout is rejected before compiler discovery (resolve_wavec) is invoked, which is one of the acceptance criteria in #585, and its table-driven coverage is a little broader.

So this PR is not being rejected because the implementation is incorrect. Both approaches solve the bug, but since the changes overlap, I am going to proceed with #586 as the cleaner and more complete implementation and close this one as a duplicate.

Thanks for working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reject non-finite and non-positive corpus checker timeouts

2 participants