git-ecosystem/git-credential-manager · error · ArgumentOutOfRangeException

Argument must be greater than or equal to

Error message

Argument must be greater than or equal to {lower}.

What it means

This ArgumentOutOfRangeException is thrown by EnsureArgument.InRange when the argument is below the lower bound while lowerInclusive is true. The value must satisfy arg >= lower. The interpolated message includes the actual lower bound, and the parameter name is attached to the exception.

Solutions

  1. Check the value against the expected lower bound before the call and clamp or correct it
  2. Fix the computation that yields a below-range value (e.g., handle a -1 not-found sentinel before indexing)
  3. Correct the config/env value to be within the documented minimum
  4. Verify you passed the bounds in the right order (lower, upper) - swapped bounds cause confusing failures

Example fix

// before
EnsureArgument.InRange(index, nameof(index), 0, list.Count - 1); // index == -1
// after
if (index >= 0)
    EnsureArgument.InRange(index, nameof(index), 0, list.Count - 1);
Defensive patterns

Strategy: validation

Validate before calling

if (value < lower) throw new InvalidOperationException($"{name} must be >= {lower}, was {value}");
// or: value = Math.Max(lower, value);

Type guard

static bool IsInRange(int v, int lower, int upper) => v >= lower && v <= upper;

Try / catch

try { EnsureArgument.InRange(index, nameof(index), 0, list.Count - 1); }
catch (ArgumentOutOfRangeException ex)
{
    logger.LogWarning("{Param}={Value} out of range; skipping item", ex.ParamName, index);
    return null; // fallback
}

Prevention

When it happens

Trigger: Calling EnsureArgument.InRange(arg, name, lower, upper) (default lowerInclusive: true) with arg < lower, e.g., a negative index into an array whose lower bound is 0, or a config value below the allowed minimum.

Common situations: Off-by-one errors where an exclusive bound was computed as inclusive; config values below a documented minimum; zero-based index calculations returning -1 for not-found.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11). Data as JSON: /api/errors/2a25d11e196c527d. Report an issue: GitHub.

Appendix: source

Thrown at src/Core/EnsureArgument.cs:81

            if (arg > 0)
            {
                throw new ArgumentOutOfRangeException(name, "Argument must be negative or zero (non-positive).");
            }
        }

        public static void Negative(int arg, string name)
        {
            if (arg >= 0)
            {
                throw new ArgumentOutOfRangeException(name, "Argument must be negative.");
            }
        }

        public static void InRange(int arg, string name, int lower, int upper, bool lowerInclusive = true, bool upperInclusive = true)
        {
            if (lowerInclusive && arg < lower)
            {
                throw new ArgumentOutOfRangeException(name, $"Argument must be greater than or equal to {lower}.");
            }

            if (!lowerInclusive && arg <= lower)
            {
                throw new ArgumentOutOfRangeException(name, $"Argument must be strictly greater than {lower}.");
            }

            if (upperInclusive && arg > upper)
            {
                throw new ArgumentOutOfRangeException(name, $"Argument must be less than or equal to {upper}.");
            }

            if (!upperInclusive && arg >= upper)
            {
                throw new ArgumentOutOfRangeException(name, $"Argument must be strictly less than {upper}.");
            }
        }
    }

View on GitHub (pinned to e8ce762cd0)