git-ecosystem/git-credential-manager · error · ArgumentOutOfRangeException
Argument must be negative.
Error message
Argument must be negative.
What it means
This ArgumentOutOfRangeException is thrown by EnsureArgument.Negative when an int argument is zero or positive. The parameter must be strictly negative (< 0), which is rare and usually indicates a sign-sensitive value such as a negative offset. The parameter name is included in the exception.
Solutions
- Ensure the value is < 0 (note: 0 also fails - use NegativeOrZero if zero is acceptable)
- Negate the computed value if the sign convention was misapplied
- Fix the upstream computation or config producing a non-negative value
- Re-read the API documentation for the strict-negative requirement
Example fix
// before
EnsureArgument.Negative(delta, nameof(delta)); // delta = 0
// after
if (delta >= 0)
delta = -1; // or handle zero as a distinct case
EnsureArgument.Negative(delta, nameof(delta)); Defensive patterns
Strategy: validation
Validate before calling
if (value >= 0) value = -1; // or handle explicitly EnsureArgument.Negative(value, nameof(value));
Type guard
static bool IsNegative(int v) => v < 0;
Try / catch
try { EnsureArgument.Negative(delta, nameof(delta)); }
catch (ArgumentOutOfRangeException ex)
{
throw new InvalidOperationException($"{ex.ParamName} must be strictly < 0 (zero not allowed), was {delta}", ex);
} Prevention
- Remember 0 fails strict-negative checks; use NegativeOrZero if zero is valid
- Negate magnitudes deliberately with -Math.Abs(x) when a negative value is required
- Verify sign conventions before calling sign-sensitive APIs
- Check config files for values that should be negative
When it happens
Trigger: Calling EnsureArgument.Negative(arg, name) with arg >= 0, e.g., passing 0 where a strictly negative value is demanded, or a sign error in offset/delta computation.
Common situations: Misunderstanding a strict-negative requirement and passing 0; flipped subtraction order; config values that should be negative entered positive.
Related errors
- Argument must be positive or zero (non-negative).
- Argument must be positive.
- Argument must be negative or zero (non-positive).
- Must specify at least one AuthenticationModes
- Argument cannot be empty or white space.
AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11).
Data as JSON: /api/errors/f276025bdcddf6ac.
Report an issue: GitHub.
Appendix: source
Thrown at src/Core/EnsureArgument.cs:73
if (arg <= 0)
{
throw new ArgumentOutOfRangeException(name, "Argument must be positive.");
}
}
public static void NegativeOrZero(int arg, string name)
{
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}.");View on GitHub (pinned to e8ce762cd0)