git-ecosystem/git-credential-manager · error · Trace2InvalidOperationException

Missing 'username' request argument

Error message

Missing 'username' request argument

What it means

StoreCommand.EnsureMinimumRequest (extending the base validation) requires a 'username' argument when storing credentials. Because empty-string usernames/passwords are legitimate, only null (argument not provided at all) is rejected. The store operation cannot proceed without knowing which account to record.

Solutions

  1. Add a `username=<name>` line to the credential input before invoking store.
  2. When building a GitRequest in code, set request.UserName explicitly (empty string is valid, null is not).
  3. If the account genuinely has no username, pass an empty value (`username=`) rather than omitting the line.
  4. Check upstream tooling/output is complete when piping between commands.

Example fix

// before (programmatic store request missing username)
var request = new GitRequest { Protocol = "https", Host = "github.com", Password = "token" };

// after
var request = new GitRequest { Protocol = "https", Host = "github.com", UserName = "octocat", Password = "token" };
Defensive patterns

Strategy: validation

Validate before calling

if (request.UserName is null)
    throw new ArgumentException("username is required for store (empty string is allowed)");

Type guard

bool HasUserName(GitRequest r) => r.UserName is not null;

Try / catch

try
{
    await storeCommand.ExecuteAsync(input);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("'username'"))
{
    // add the username field and re-run store
}

Prevention

When it happens

Trigger: Calling `git credential-manager store` (or the store command path) where the credential input lacks a `username=` line, so request.UserName is null after base validation passed.

Common situations: Automation that stores credentials programmatically omitting the username field; hand-crafted credential inputs for testing; scripts that only pipe password data; users running store commands manually with incomplete input.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11). Data as JSON: /api/errors/42e852b74bfa7666. Report an issue: GitHub.

Appendix: source

Thrown at src/Core/Commands/StoreCommand.cs:29

        public StoreCommand(ICommandContext context, IHostProviderRegistry hostProviderRegistry)
            : base(context, "store", "[Git] Store a credential", hostProviderRegistry)
        {
            IsHidden = true;
        }

        protected override Task ExecuteInternalAsync(GitRequest request, IHostProvider provider)
        {
            return provider.StoreCredentialAsync(request);
        }

        protected override void EnsureMinimumRequest(GitRequest request)
        {
            base.EnsureMinimumRequest(request);

            // An empty string username/password are valid inputs, so only check for `null` (not provided)
            if (request.UserName is null)
            {
                throw new Trace2InvalidOperationException(Context.Trace2, "Missing 'username' request argument");
            }

            if (request.Password is null)
            {
                throw new Trace2InvalidOperationException(Context.Trace2, "Missing 'password' request argument");
            }
        }
    }
}

View on GitHub (pinned to e8ce762cd0)