oracletrace icon indicating copy to clipboard operation
oracletrace copied to clipboard

[Bug]: --top integer parsing / validation bug

Open KaykCaputo opened this issue 7 months ago • 2 comments

Summary

--top is not reliably validated as a positive integer and can behave incorrectly for invalid values (and an existing test may be masking the bug).

Expected Behavior

  • --top only accepts a positive integer.
  • Invalid values (non-integers, 0, negatives) fail with a clear error message on stderr and a non-zero exit code.

Actual Behavior

--top accepts invalid input or fails in an unclear way (parsing/typing bug).

Steps to Reproduce

Try:

  • oracletrace your_script.py --top foo
  • oracletrace your_script.py --top 0
  • oracletrace your_script.py --top -5

Proposed Solution

  • Enforce --top as a positive integer at argument parsing level
  • Print a friendly error to stderr and exit non-zero
  • Fix/replace the test that currently masks the issue

Acceptance Criteria

  • Invalid --top values are rejected with stderr + non-zero exit
  • Valid values work and correctly limit output
  • Tests cover valid/invalid cases

Affected Files

  • oracletrace/cli.py
  • tests/test_cli.py

KaykCaputo avatar Apr 17 '26 12:04 KaykCaputo

Hi, I'd like to work on this issue.

I've identified the root cause: on cli.py:91, int(args.top[0]) indexes into the string, so --top 10 becomes int("1") = 1 instead of 10. The fix is to use type=int in argparse and add a validation check for positive values, plus redirect error messages to stderr. I'll submit a PR shortly.

CrepuscularIRIS avatar Apr 18 '26 07:04 CrepuscularIRIS

Hi @CrepuscularIRIS ! Very nice, I thought it was something like that. Feel free to work on this and let me know if you have any questions. Thanks!

KaykCaputo avatar Apr 18 '26 13:04 KaykCaputo