Skip to content

Reject --for durations longer than a wait can take - #15

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/cap-for-duration
Sep 27, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/cap-for-duration

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #14

What changed

DurationParser used to accept any positive duration up to TimeSpan.MaxValue. ConsoleRunner.Run's ManualResetEventSlim.Wait(TimeSpan) and the tray's DispatcherTimer both reject anything over int.MaxValue ms (about 24.8 days). As a result, --for 25d printed its start message and then crashed with an unhandled ArgumentOutOfRangeException.

  • The new DurationParser.MaxDuration is TimeSpan.FromMilliseconds(int.MaxValue). TryParse now returns false for anything longer, so both the console path and the tray path are covered.
  • The new internal DurationParser.TryParseAnyLength holds the unbounded parse. CommandLineParser uses it so it can tell "too long" apart from "not a duration". --for 25d now fails at argument parsing with '25d' is too long: --for can be at most 24 days.

MaxDuration is a new public member. The change is additive, and the package-validation build passes.

Tests

  • DurationParserTests:
    • 24d still parses.
    • 25d and 24d21h (just past the limit) are rejected.
    • MaxDuration_IsTheLongestTimeoutAWaitTakes checks the boundary against a real ManualResetEventSlim: a wait of MaxDuration is accepted, and a wait of MaxDuration + 1ms throws.
  • CommandLineParserTests.TryParse_WithADurationLongerThanATimerCanWait_FailsWithAUsageError covers the usage message.

With the cap temporarily removed, the three new rejection tests fail. With it in place, the full suite passes on Linux/net10.0: 117 passed, 1 skipped.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CGpRxGxuvhstHo5zXQoWSA


Generated by Claude Code

DurationParser accepted anything up to TimeSpan.MaxValue, but the
console runner's ManualResetEventSlim.Wait and the tray's timer both
throw past int.MaxValue milliseconds (about 24.8 days), so `--for 25d`
started the tool and then crashed it with an unhandled exception. Cap
TryParse at DurationParser.MaxDuration, and have the command line report
a too-long value as a usage error rather than as "not a duration".

Fixes #14

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CGpRxGxuvhstHo5zXQoWSA
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 0ffbb56 into main Sep 27, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the claude/cap-for-duration branch September 27, 2026 00:19
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.

--for 25d (any duration over ~24.8 days) crashes console mode with an unhandled ArgumentOutOfRangeException

2 participants