git-ecosystem/git-credential-manager · error · ArgumentException
Argument cannot be empty.
Error message
Argument cannot be empty.
What it means
EnsureArgument.NotNullOrEmpty first delegates to NotNull (throwing ArgumentNullException for null) and then throws ArgumentException("Argument cannot be empty.", name) when the string is empty. It is GCM's standard guard for required string arguments that must carry content.
Solutions
- Identify the offending parameter from the ArgumentException ParamName and ensure the caller supplies a non-empty value.
- Coerce empty settings to a meaningful default before calling the API.
- Trim and validate user/script input before passing it to GCM.
Example fix
// before EnsureArgument.NotNullOrEmpty(userName, nameof(userName)); // userName == "" // after if (string.IsNullOrWhiteSpace(userName)) userName = Environment.UserName; EnsureArgument.NotNullOrEmpty(userName, nameof(userName));
Defensive patterns
Strategy: validation
Validate before calling
if (typeof arg !== 'string' || arg.length === 0) {
throw new Error(`Required string argument '${name}' must be non-empty`);
} Type guard
function isNonEmptyString(v: unknown): v is string {
return typeof v === 'string' && v.length > 0;
} Try / catch
try {
gcmApi(value, name);
} catch (ArgumentException ex) when (ex.ParamName == name) {
// supply a default or surface a user-facing validation message
} Prevention
- Treat blank env vars and .gitconfig values as unset and substitute defaults
- Trim user input and reject empty strings at the boundary
- Use string.IsNullOrWhiteSpace checks before calling guarded APIs
When it happens
Trigger: Passing "" (empty string, not null) to any GCM API guarded by EnsureArgument.NotNullOrEmpty — e.g. empty host names, empty account/credential fields, or empty config values read from settings.
Common situations: Empty environment variables or .gitconfig values (set but blank) passed into GCM; splitting/parsing operations yielding empty strings; UI or scripts passing empty arguments to credential operations.
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
- ObjectDisposedException(GetType().Name)
- Argument cannot be empty or white space.
- Argument must be an absolute URI.
- Argument must be positive or zero (non-negative).
AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11).
Data as JSON: /api/errors/af094d9da789e80a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Core/EnsureArgument.cs:21
namespace GitCredentialManager
{
public static class EnsureArgument
{
public static void NotNull<T>(T arg, string name)
{
if (arg is null)
{
throw new ArgumentNullException(name);
}
}
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)View on GitHub (pinned to e8ce762cd0)