git-ecosystem/git-credential-manager · error · ArgumentOutOfRangeException
Argument must be negative or zero (non-positive).
Error message
Argument must be negative or zero (non-positive).
What it means
This ArgumentOutOfRangeException is thrown by EnsureArgument.NegativeOrZero when an int argument is positive. The parameter is expected to be non-positive (<= 0), which is uncommon and typically used for offsets, decrements, or temperature-like scales where only zero or negative values are meaningful.
Solutions
- Verify the sign convention of the API you are calling and negate the value if needed
- Fix the computation producing a positive value (e.g., use Math.Min(0, value) or correct operand order)
- Check config sign conventions and document them
- Review recent changes that may have flipped a subtraction
Example fix
// before EnsureArgument.NegativeOrZero(offset, nameof(offset)); // offset = 5 // after var adjustedOffset = -Math.Abs(offset); EnsureArgument.NegativeOrZero(adjustedOffset, nameof(adjustedOffset));
Defensive patterns
Strategy: validation
Validate before calling
if (value > 0) value = -value; // enforce sign convention EnsureArgument.NegativeOrZero(value, nameof(value));
Type guard
static bool IsNonPositive(int v) => v <= 0;
Try / catch
try { EnsureArgument.NegativeOrZero(offset, nameof(offset)); }
catch (ArgumentOutOfRangeException ex)
{
throw new InvalidOperationException($"{ex.ParamName} must be <= 0, was {offset}; check sign convention", ex);
} Prevention
- Document sign conventions for offsets/deltas in API docs
- Use Math.Min(0, x) to enforce non-positive results
- Check subtraction operand order when computing negative-going values
- Validate config signs (e.g., negative offsets) at startup
When it happens
Trigger: Calling EnsureArgument.NegativeOrZero(arg, name) with arg > 0, e.g., sign-flipped math, subtracting in the wrong direction, or passing a magnitude where a negative offset was required.
Common situations: Sign errors when computing offsets or adjustments; passing a positive step to an API expecting a backward decrement; a config value that should be negative (e.g., timezone offset west) entered as positive.
Related errors
- Argument must be positive or zero (non-negative).
- Argument must be positive.
- Argument must be negative.
- 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/35e319335fd75b8d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Core/EnsureArgument.cs:65
if (arg < 0)
{
throw new ArgumentOutOfRangeException(name, "Argument must be positive or zero (non-negative).");
}
}
public static void Positive(int arg, string name)
{
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}.");
}
View on GitHub (pinned to e8ce762cd0)