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

Missing 'username' in response

Error message

Missing 'username' in response

What it means

The configured credential helper command was invoked successfully but its response dictionary contained no 'username' key, so BasicAuthentication cannot construct a GitCredential. This indicates a broken or non-conformant credential helper.

Solutions

  1. Verify the helper prints username=... and password=... lines on stdout (test it manually with the same command/args)
  2. Fix or replace the non-conformant helper script
  3. Reconfigure credential.helper to a known-good helper (e.g. GCM itself or git-credential-store)
  4. Check the helper isn't swallowing output or prompting when it should print

Example fix

# before (custom helper prints JSON)
echo '{"username":"u","password":"p"}'
# after (Git helper protocol)
echo "username=$USER"
echo "password=$PASS"
Defensive patterns

Strategy: validation

Validate before calling

// test helper output before use
var output = RunHelper(command, args);
if (!output.Contains("username=")) throw new InvalidOperationException("Helper does not emit username=");

Try / catch

try { /* get creds via helper */ }
catch (Trace2Exception ex) when (ex.Message.Contains("Missing 'username'")) { /* reconfigure or repair helper */ }

Prevention

When it happens

Trigger: GetCredentialsViaHelperAsync calls InvokeHelperAsync and then TryGetValue("username", out userName); the helper's stdout did not include username=..., so the throw fires.

Common situations: A custom or third-party credential helper that does not emit Git's key=value protocol; a helper that exits successfully but prints nothing (e.g. it tried to prompt in a headless environment); a misconfigured helper path pointing at the wrong program.

Related errors


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

Appendix: source

Thrown at src/Core/Authentication/BasicAuthentication.cs:115

        {
            var promptArgs = new StringBuilder(args);
            promptArgs.Append("basic");

            if (!string.IsNullOrWhiteSpace(resource))
            {
                promptArgs.AppendFormat(" --resource {0}", QuoteCmdArg(resource));
            }

            if (!string.IsNullOrWhiteSpace(userName))
            {
                promptArgs.AppendFormat(" --username {0}", QuoteCmdArg(userName));
            }

            IDictionary<string, string> resultDict = await InvokeHelperAsync(command, promptArgs.ToString(), null);

            if (!resultDict.TryGetValue("username", out userName))
            {
                throw new Trace2Exception(Context.Trace2, "Missing 'username' in response");
            }

            if (!resultDict.TryGetValue("password", out string password))
            {
                throw new Trace2Exception(Context.Trace2, "Missing 'password' in response");
            }

            return new GitCredential(userName, password);
        }

        private bool TryFindHelperCommand(out string command, out string args)
        {
            return TryFindHelperCommand(
                Constants.EnvironmentVariables.GcmUiHelper,
                Constants.GitConfiguration.Credential.UiHelper,
                Constants.DefaultUiHelper,
                out command,
                out args);

View on GitHub (pinned to e8ce762cd0)