Skip to content

Report an out-of-range number for an option as a usage error [patch] - #70

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/69-overflow-is-a-usage-error
Nov 4, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/69-overflow-is-a-usage-error

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

TryApplyOptions turned a value handler's exception into the usage error only for FormatException and ArgumentException. The most natural handler, v => count = int.Parse(v, CultureInfo.InvariantCulture), throws OverflowException for 99999999999. That exception escaped and the tool crashed with exit 134 instead of printing the usage line and exiting 2. The same applies to long.Parse, byte.Parse, decimal.Parse and checked conversions.

Change

  • TrayAppBuilder.TryApplyOptions also treats OverflowException as a usage error.
  • The README sentence that documents the contract now names OverflowException too.

I kept the explicit list rather than catching every non-fatal exception, so a handler bug such as a NullReferenceException still surfaces as a bug rather than as "bad input".

Tests

  • New TryApplyOptions_WhenAHandlerParsesAnOutOfRangeNumber_ReportsItAsAUsageError uses a real int.Parse handler with --count 99999999999, and expects false plus the overflow message.
  • With the fix reverted, the new test fails with the unhandled OverflowException. With it, the suite passes: 161 passed, plus 1 skipped that is platform-gated (DesktopSession_OffLinux_IsAlwaysAvailable).
  • Checked locally: the branch merges cleanly with every other open branch in the repo.

Fixes #69


Generated by Claude Code

int.Parse and its relatives throw OverflowException, not FormatException,
for a number too large for the type, so `--count 99999999999` escaped
TryApplyOptions as an unhandled exception and the tool exited 134 instead
of printing the usage error and exiting 2.

Fixes #69

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

sonarqubecloud Bot commented Nov 1, 2026

Copy link
Copy Markdown

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.

An out-of-range number for an int.Parse option (--count 99999999999) crashes the tool with exit 134 instead of the usage error and exit 2

2 participants