{"record":{"id":"42e852b74bfa7666","repo":"git-ecosystem/git-credential-manager","slug":"missing-username-request-argument","errorCode":null,"errorMessage":"Missing 'username' request argument","messagePattern":"Missing 'username' request argument","errorType":"exception","errorClass":"Trace2InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Core/Commands/StoreCommand.cs","lineNumber":29,"sourceCode":"        public StoreCommand(ICommandContext context, IHostProviderRegistry hostProviderRegistry)\n            : base(context, \"store\", \"[Git] Store a credential\", hostProviderRegistry)\n        {\n            IsHidden = true;\n        }\n\n        protected override Task ExecuteInternalAsync(GitRequest request, IHostProvider provider)\n        {\n            return provider.StoreCredentialAsync(request);\n        }\n\n        protected override void EnsureMinimumRequest(GitRequest request)\n        {\n            base.EnsureMinimumRequest(request);\n\n            // An empty string username/password are valid inputs, so only check for `null` (not provided)\n            if (request.UserName is null)\n            {\n                throw new Trace2InvalidOperationException(Context.Trace2, \"Missing 'username' request argument\");\n            }\n\n            if (request.Password is null)\n            {\n                throw new Trace2InvalidOperationException(Context.Trace2, \"Missing 'password' request argument\");\n            }\n        }\n    }\n}\n","sourceCodeStart":11,"sourceCodeEnd":39,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/Commands/StoreCommand.cs#L11-L39","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add a `username=<name>` line to the credential input before invoking store.","When building a GitRequest in code, set request.UserName explicitly (empty string is valid, null is not).","If the account genuinely has no username, pass an empty value (`username=`) rather than omitting the line.","Check upstream tooling/output is complete when piping between commands."],"exampleFix":"// before (programmatic store request missing username)\nvar request = new GitRequest { Protocol = \"https\", Host = \"github.com\", Password = \"token\" };\n\n// after\nvar request = new GitRequest { Protocol = \"https\", Host = \"github.com\", UserName = \"octocat\", Password = \"token\" };","handlingStrategy":"validation","validationCode":"if (request.UserName is null)\n    throw new ArgumentException(\"username is required for store (empty string is allowed)\");","typeGuard":"bool HasUserName(GitRequest r) => r.UserName is not null;","tryCatchPattern":"try\n{\n    await storeCommand.ExecuteAsync(input);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"'username'\"))\n{\n    // add the username field and re-run store\n}","preventionTips":["Include username= in every store payload, even if empty.","Distinguish null vs empty-string semantics in request builders.","Verify token/account data is fully propagated through pipelines.","Test store command with both empty and non-empty usernames."],"tags":["git","credential-store","missing-argument","request-validation"],"backgroundTag":"missing-required-argument","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"}