Skip to content

Out-of-range numeric flags (--limit -1, --depth 999999) silently coerced without error #1700

Description

@Widthdom

Summary

When the user passes nonsense numeric values like --limit -1, --limit 0, --depth 999999999, or --snippet-lines -5, the parser currently silently coerces (clamps) the value to the default or a min/max bound and proceeds without printing any error. This is distinct from #184, which describes the path where a validation error IS printed but the command continues with default and exit=0. The bug here is that no validation runs at all on these specific code paths — clamp happens silently and the user has no signal that their input was rejected.

Where

  • src/CodeIndex/Cli/QueryCommandRunner.cs:2756-2766 (--limit parse, no min/max validation, value silently coerced downstream)
  • src/CodeIndex/Cli/QueryCommandRunner.cs:2834-2844 (--depth parse, similar)
  • Surrounding numeric flag parsers across the file

Suggested approach

(1) Centralize numeric flag parsing in a helper TryParseBoundedInt(arg, min, max, out value, out error). (2) For each numeric flag, declare its valid range (e.g., --limit ∈ [1, 10000], --depth ∈ [0, 100], --snippet-lines ∈ [0, 1000]). (3) On out-of-range, fail-fast with exit code 64 (EX_USAGE) and a one-line error pointing to the flag and the valid range. (4) Apply consistently across both QueryCommandRunner and IndexCommandRunner. (5) Cover with regression tests for each flag's lower-bound, upper-bound, and zero-edge cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions