Skip to content

Reject a preference debounce a timer cannot wait for when it is configured [patch] - #44

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/36-validate-preference-debounce
Oct 9, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/36-validate-preference-debounce

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #36

What changed

TrayAppBuilder.Preferences(..., debounce:) stored any value it was given. Nothing used it until the first click on a persisted toggle. At that point DebouncedPreferenceStore.Set called Timer.Change, which threw ArgumentOutOfRangeException out of the tray's click handler, after the toggle's setter had already run. The error only showed up in tray mode, so tests never caught it.

Preferences now throws ArgumentOutOfRangeException (ParamName == "debounce") when the tool is configured, for:

Zero and null (half a second) are still accepted. The XML doc gains an <exception> entry, and the README API table states the range.

Tests

  • Preferences_WithADebounceATimerCannotWaitFor_Throws covers -1000 ms, -1 ms and 60 days.
  • Preferences_WithAnInfiniteDebounce_Throws.
  • Preferences_WithZeroOrNoDebounce_IsAccepted checks that PreferenceDebounce is 0, and 500 ms when no value is given.
  • Preferences_WithTheLongestDebounce_IsAcceptedAndATimerTakesIt passes the maximum through to a real DebouncedPreferenceStore.Set, which proves the limit is the timer's own.
  • With the check disabled, the 4 rejection tests fail. With it in place, the full suite passes (145 passed, 1 skipped as before, net10.0 on Linux), and the library builds for net10.0 and net9.0.

This PR is independent of #43 (#38). Both branch from main.

🤖 Generated with Claude Code

https://claude.ai/code/session_011eecgtNA1yFm2UXzPrxvEg


Generated by Claude Code

…gured [patch]

Preferences stored any debounce, and nothing used it until the first click
on a persisted toggle, when Timer.Change threw ArgumentOutOfRangeException
out of the tray's click handler, after the toggle's setter had already
run. Preferences now throws ArgumentOutOfRangeException (param debounce)
for a negative value, Timeout.InfiniteTimeSpan, or more than the ~49.7
days a timer can wait. Infinite is refused because it means "write only
at exit", and an exit by SIGTERM does not flush (#21).

Fixes #36

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

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 0168564 into main Oct 9, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants