git-ecosystem/git-credential-manager · error · Trace2Exception
Missing 'username' in response
Error message
Missing 'username' in response
What it means
For response mode 'basic', the helper must return both 'username' and 'password'. This exception is thrown when mode=basic arrives without a 'username' key, meaning the helper's basic-auth prompt produced no username. The credential pair is incomplete, so the method cannot return a valid AuthenticationPromptResult.
Solutions
- Upgrade GCM/helper to a consistent version and retry authentication
- Complete the basic auth dialog fully (enter username and password) instead of dismissing it
- Use an alternative auth mode (browser, device, or PAT) that avoids the basic prompt
- If implementing a custom helper, always emit username and password together with mode=basic
Example fix
// before
output["mode"] = "basic"; // username/password possibly unset
// after
if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
{
output["mode"] = "basic";
output["username"] = username;
output["password"] = password;
} Defensive patterns
Strategy: try-catch
Validate before calling
// Prefer modes that do not require the basic username prompt when helper contract is uncertain
var supported = new[] { "browser", "device", "pat" };
// configure GCM to use a non-basic mode:
// git config --global credential.github.com.gitHubAuthModes browser,pat,device Try / catch
try
{
var result = await auth.GetAuthenticationAsync(uri, userName);
}
catch (Trace2Exception ex) when (ex.Message.StartsWith("Missing 'username'"))
{
trace.WriteLine("Basic auth helper response missing username; falling back to another mode.");
throw;
} Prevention
- Complete both username and password fields in the basic auth dialog
- Configure preferred auth modes (browser/pat) to avoid the basic prompt entirely
- Keep helper and core versions matched
- Validate custom helper output emits username+password together with mode=basic
When it happens
Trigger: Helper returns mode=basic but the dictionary lacks 'username': the basic auth dialog was dismissed after mode selection, a custom helper omitted the key, or output parsing dropped it.
Common situations: Users pressing Cancel on the username field of the basic auth dialog with a nonconforming helper; custom or older helper builds that don't emit all basic-mode keys; locale/encoding issues corrupting key output.
Related errors
- Missing 'password' in response
- Missing 'pat' in response
- Unknown mode value in response
- Missing 'mode' in response
- Missing 'code' in response
AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11).
Data as JSON: /api/errors/5c330c60b46b2af0.
Report an issue: GitHub.
Appendix: source
Thrown at src/GitHub/GitHubAuthentication.cs:332
case "pat":
if (!resultDict.TryGetValue("pat", out string pat))
{
throw new Trace2Exception(Context.Trace2, "Missing 'pat' in response");
}
return new AuthenticationPromptResult(
AuthenticationModes.Pat, new GitCredential(userName, pat));
case "browser":
return new AuthenticationPromptResult(AuthenticationModes.Browser);
case "device":
return new AuthenticationPromptResult(AuthenticationModes.Device);
case "basic":
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 AuthenticationPromptResult(
AuthenticationModes.Basic, new GitCredential(userName, password));
default:
throw new Trace2Exception(Context.Trace2,
$"Unknown mode value in response '{responseMode}'");
}
}
public async Task<string> GetTwoFactorCodeAsync(Uri targetUri, bool isSms)
{View on GitHub (pinned to e8ce762cd0)