git-ecosystem/git-credential-manager · error · Trace2Exception
Missing 'username' in response
Error message
Missing 'username' in response
What it means
Thrown in GetAuthenticationViaHelperAsync when the helper response declares `mode=basic` but no 'username' key is present. Basic-mode responses must supply both username and password so GCM can construct a GitCredential.
Solutions
- Make the helper emit `username=` exactly (key name is case-sensitive) alongside `mode=basic`.
- Verify the helper's account/username variable is not empty before printing the response.
- Use `mode=pat` instead of `mode=basic` if only a token (no username/password pair) is available.
Example fix
// before echo "mode=basic" echo "user=$USER" // after echo "mode=basic" echo "username=$USER" echo "password=$PASS"
Defensive patterns
Strategy: validation
Validate before calling
// Check both basic fields exist before declaring basic mode if [ -z "$USER" ] || [ -z "$PASS" ]; then echo "Error: missing basic credentials" >&2; exit 1; fi echo "mode=basic" echo "username=$USER" echo "password=$PASS"
Try / catch
try {
var result = await auth.GetAuthenticationAsync(...);
} catch (Trace2Exception ex) when (ex.Message.Contains("Missing 'username' in response")) {
// prompt for username interactively as fallback
} Prevention
- Use the exact key names: username and password
- Test the helper end-to-end with a real GitLab account
- Prefer mode=pat when only a token is available
When it happens
Trigger: Helper emits `mode=basic` and `password=...` but omits `username=`; a helper that handles PAT-only flows incorrectly reporting basic mode.
Common situations: Custom basic-auth helpers for self-hosted GitLab that skip the username prompt; scripts passing only an account email in a differently-named key (e.g. `user=` instead of `username=`).
Related errors
- Missing 'password' in response
- Missing 'mode' in response
- Missing 'pat' in response
- Unknown mode value in response
- Missing 'username' in response
AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11).
Data as JSON: /api/errors/2a304c78e18f6955.
Report an issue: GitHub.
Appendix: source
Thrown at src/GitLab/GitLabAuthentication.cs:244
{
throw new Trace2Exception(Context.Trace2, "Missing 'pat' in response");
}
if (!resultDict.TryGetValue("username", out string patUserName))
{
// Username is optional for PATs
}
return new AuthenticationPromptResult(
AuthenticationModes.Pat, new GitCredential(patUserName, pat));
case "browser":
return new AuthenticationPromptResult(AuthenticationModes.Browser);
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<OAuth2TokenResult> GetOAuthTokenViaBrowserAsync(Uri targetUri, IEnumerable<string> scopes)
{View on GitHub (pinned to e8ce762cd0)