{"record":{"id":"2a304c78e18f6955","repo":"git-ecosystem/git-credential-manager","slug":"missing-username-in-response-2a304c","errorCode":null,"errorMessage":"Missing 'username' in response","messagePattern":"Missing 'username' in response","errorType":"exception","errorClass":"Trace2Exception","httpStatus":null,"severity":"error","filePath":"src/GitLab/GitLabAuthentication.cs","lineNumber":244,"sourceCode":"                    {\n                        throw new Trace2Exception(Context.Trace2, \"Missing 'pat' in response\");\n                    }\n\n                    if (!resultDict.TryGetValue(\"username\", out string patUserName))\n                    {\n                        // Username is optional for PATs\n                    }\n\n                    return new AuthenticationPromptResult(\n                        AuthenticationModes.Pat, new GitCredential(patUserName, pat));\n\n                case \"browser\":\n                    return new AuthenticationPromptResult(AuthenticationModes.Browser);\n\n                case \"basic\":\n                    if (!resultDict.TryGetValue(\"username\", out userName))\n                    {\n                        throw new Trace2Exception(Context.Trace2, \"Missing 'username' in response\");\n                    }\n\n                    if (!resultDict.TryGetValue(\"password\", out string password))\n                    {\n                        throw new Trace2Exception(Context.Trace2, \"Missing 'password' in response\");\n                    }\n\n                    return new AuthenticationPromptResult(\n                        AuthenticationModes.Basic, new GitCredential(userName, password));\n\n                default:\n                    throw new Trace2Exception(Context.Trace2,\n                        $\"Unknown mode value in response '{responseMode}'\");\n            }\n        }\n\n        public async Task<OAuth2TokenResult> GetOAuthTokenViaBrowserAsync(Uri targetUri, IEnumerable<string> scopes)\n        {","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/GitLab/GitLabAuthentication.cs#L226-L262","documentation":"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.","triggerScenarios":"Helper emits `mode=basic` and `password=...` but omits `username=`; a helper that handles PAT-only flows incorrectly reporting basic mode.","commonSituations":"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=`).","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."],"exampleFix":"// before\necho \"mode=basic\"\necho \"user=$USER\"\n// after\necho \"mode=basic\"\necho \"username=$USER\"\necho \"password=$PASS\"","handlingStrategy":"validation","validationCode":"// Check both basic fields exist before declaring basic mode\nif [ -z \"$USER\" ] || [ -z \"$PASS\" ]; then echo \"Error: missing basic credentials\" >&2; exit 1; fi\necho \"mode=basic\"\necho \"username=$USER\"\necho \"password=$PASS\"","typeGuard":null,"tryCatchPattern":"try {\n  var result = await auth.GetAuthenticationAsync(...);\n} catch (Trace2Exception ex) when (ex.Message.Contains(\"Missing 'username' in response\")) {\n  // prompt for username interactively as fallback\n}","preventionTips":["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"],"tags":["gitlab","credential-helper","basic-auth"],"backgroundTag":"missing-credentials","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}