git-ecosystem/git-credential-manager · error · ArgumentException
Argument cannot be empty or white space.
Error message
Argument cannot be empty or white space.
What it means
This ArgumentException is thrown by EnsureArgument.NotNullOrWhiteSpace when a required string argument is null, empty, or contains only whitespace. The library treats empty/whitespace strings as invalid because downstream code depends on a meaningful value. The parameter name is passed to ArgumentException so the caller can identify the offending argument.
Solutions
- Ensure the string argument is non-empty and contains at least one non-whitespace character before calling the API that validates it
- Check the source of the value (config file, env var, user input) and fix the upstream producer that yields an empty/whitespace value
- If null is the issue, note the message comes from NotNull first; supply an actual string object
- Add validation or defaults at application startup so blank values fail early with a clearer message
Example fix
// before
EnsureArgument.NotNullOrWhiteSpace(apiKey, nameof(apiKey)); // throws when apiKey = " "
// after
if (string.IsNullOrWhiteSpace(apiKey))
throw new InvalidOperationException("apiKey must be configured; set API_KEY env var");
EnsureArgument.NotNullOrWhiteSpace(apiKey, nameof(apiKey)); Defensive patterns
Strategy: validation
Validate before calling
public static bool IsValidNonWhiteSpace(string s) => !string.IsNullOrWhiteSpace(s);
// usage: if (!IsValidNonWhiteSpace(apiKey)) throw new InvalidOperationException("apiKey required"); Type guard
static bool HasValue(string? s) => !string.IsNullOrWhiteSpace(s);
Try / catch
try { EnsureArgument.NotNullOrWhiteSpace(value, nameof(value)); }
catch (ArgumentException ex) when (ex.ParamName == nameof(value))
{
logger.LogWarning("Value for {Param} was empty; using default", ex.ParamName);
value = defaultValue;
} Prevention
- Check string.IsNullOrWhiteSpace at config-load time and fail fast with a clear message
- Use nullable reference types (string?) to force null handling at compile time
- Centralize required-string validation in one startup step
- Never pass raw env vars or user input straight into validated APIs without trimming and checking
When it happens
Trigger: Calling EnsureArgument.NotNullOrWhiteSpace(arg, name) when arg is null, "", or consists only of spaces/tabs/newlines. Note NotNull(arg, name) runs first, so a null arg throws ArgumentNullException from NotNull rather than this message.
Common situations: Passing an unset environment variable or empty config value as an API key, host, or connection string; trimming user input to an empty string; a deserialized object with a blank required field.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Must specify at least one AuthenticationModes
- Argument must be an absolute URI.
- Argument must be positive or zero (non-negative).
- Argument must be positive.
- Argument must be negative or zero (non-positive).
AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11).
Data as JSON: /api/errors/61447dd3e6ef8237.
Report an issue: GitHub.
Appendix: source
Thrown at src/Core/EnsureArgument.cs:31
}
public static void NotNullOrEmpty(string arg, string name)
{
NotNull(arg, name);
if (string.IsNullOrEmpty(arg))
{
throw new ArgumentException("Argument cannot be empty.", name);
}
}
public static void NotNullOrWhiteSpace(string arg, string name)
{
NotNull(arg, name);
if (string.IsNullOrWhiteSpace(arg))
{
throw new ArgumentException("Argument cannot be empty or white space.", name);
}
}
public static void AbsoluteUri(Uri arg, string name)
{
NotNull(arg, name);
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).");View on GitHub (pinned to e8ce762cd0)