git-ecosystem/git-credential-manager · error · ArgumentOutOfRangeException
Argument must be positive.
Error message
Argument must be positive.
What it means
This ArgumentOutOfRangeException is thrown by EnsureArgument.Positive when an int argument is zero or negative. The parameter must be strictly greater than zero (> 0), e.g., a page size, batch size, or count. The parameter name is included in the exception.
Solutions
- Ensure the value is >= 1 before the call, e.g., Math.Max(1, value) or a proper default
- Check initialization order - the value may not have been set before first use
- Fix the config/source producing 0 or a negative value
- If 0 is valid "unset", switch to int? and validate only when set
Example fix
// before EnsureArgument.Positive(batchSize, nameof(batchSize)); // batchSize defaults to 0 // after int batchSize = config.BatchSize > 0 ? config.BatchSize : DefaultBatchSize; EnsureArgument.Positive(batchSize, nameof(batchSize));
Defensive patterns
Strategy: validation
Validate before calling
if (value <= 0) throw new InvalidOperationException($"{name} must be > 0, was {value}");
// or default: value = value > 0 ? value : DefaultValue; Type guard
static bool IsPositive(int v) => v > 0;
Try / catch
try { EnsureArgument.Positive(batchSize, nameof(batchSize)); }
catch (ArgumentOutOfRangeException ex)
{
logger.LogError("{Param}={Value}; must be strictly positive", ex.ParamName, batchSize);
batchSize = DefaultBatchSize;
} Prevention
- Give non-zero defaults to fields used as counts/sizes before first use
- Never pass list.Count of an possibly-empty list where > 0 is required
- Validate batch/page-size config at startup (must be >= 1)
- Use Math.Max(1, value) as a defensive normalization
When it happens
Trigger: Calling EnsureArgument.Positive(arg, name) with arg <= 0, e.g., an uninitialized/default(int) == 0 value, an empty collection's count, or a config value of "0" or negative.
Common situations: Forgetting to initialize a field so it stays at the default 0; dividing work by a batch size that was configured as 0; taking .Count of an empty list; config placeholder "0" never replaced.
Related errors
- Argument must be positive or zero (non-negative).
- Argument must be negative or zero (non-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/88783f0f409f5bed.
Report an issue: GitHub.
Appendix: source
Thrown at src/Core/EnsureArgument.cs:57
if (!arg.IsAbsoluteUri)
{
throw new ArgumentException("Argument must be an absolute URI.", name);
}
}
public static void PositiveOrZero(int arg, string name)
{
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.");
}
}View on GitHub (pinned to e8ce762cd0)