{"record":{"id":"f0d2936cc1539533","repo":"docker/cli","slug":"error-username-is-required","errorCode":null,"errorMessage":"error: username is required","messagePattern":"error: username is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/registry.go","lineNumber":148,"sourceCode":"\n\t\tvar msg string\n\t\tdefaultUsername = strings.TrimSpace(defaultUsername)\n\t\tif defaultUsername == \"\" {\n\t\t\tmsg = \"Username: \"\n\t\t} else {\n\t\t\tmsg = fmt.Sprintf(\"Username (%s): \", defaultUsername)\n\t\t}\n\n\t\tvar err error\n\t\targUser, err = prompt.ReadInput(ctx, stdIn, cli.Out(), msg)\n\t\tif err != nil {\n\t\t\treturn registrytypes.AuthConfig{}, err\n\t\t}\n\t\tif argUser == \"\" {\n\t\t\targUser = defaultUsername\n\t\t}\n\t\tif argUser == \"\" {\n\t\t\treturn registrytypes.AuthConfig{}, errors.New(\"error: username is required\")\n\t\t}\n\t}\n\n\tisEmpty := strings.TrimSpace(argPassword) == \"\"\n\tif isEmpty {\n\t\trestoreInput, err := prompt.DisableInputEcho(stdIn)\n\t\tif err != nil {\n\t\t\treturn registrytypes.AuthConfig{}, err\n\t\t}\n\t\tdefer func() {\n\t\t\tif err := restoreInput(); err != nil {\n\t\t\t\t// TODO(thaJeztah): we should consider printing instructions how\n\t\t\t\t//  to restore this manually (other than restarting the shell).\n\t\t\t\t//  e.g., 'run stty echo' when in a Linux or macOS shell, but\n\t\t\t\t//  PowerShell and CMD.exe may need different instructions.\n\t\t\t\t_, _ = fmt.Fprintln(cli.Err(), \"Error: failed to restore terminal state to echo input:\", err)\n\t\t\t}\n\t\t}()","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/registry.go#L130-L166","documentation":"Thrown by PromptUserForCredentials after the interactive username prompt returns an empty string and no default username is available. The login flow cannot proceed without a username.","triggerScenarios":"Interactive 'docker login' where the user presses Enter at the 'Username:' prompt without typing anything and there is no stored/default username (registry.go lines 144-148).","commonSituations":"Accidental Enter at the prompt; empty DOCKER_USER env; first-time login on a fresh install.","solutions":["Type your Docker ID (or email) at the prompt and press Enter.","Pass the username explicitly: 'docker login -u <user>'.","Use a Personal Access Token (PAT) with --password-stdin for non-interactive flows."],"exampleFix":"# before (pressing Enter at Username: prompt)\ndocker login\n# after\ndocker login -u myuser","handlingStrategy":"validation","validationCode":"// Ensure a username is available before prompting\nif strings.TrimSpace(username) == \"\" && strings.TrimSpace(defaultUsername) == \"\" {\n    return fmt.Errorf(\"a username is required; pass -u or set a default\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass --username (-u) explicitly rather than relying on the prompt.","Pre-populate a default username in non-interactive flows.","Use --password-stdin with a known username for automation."],"tags":["registry","login","auth","docker","go","cli"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}