{"record":{"id":"f82757aae5be4377","repo":"amir20/dozzle","slug":"username-is-required","errorCode":null,"errorMessage":"username is required","messagePattern":"username is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/support/cli/generate_command.go","lineNumber":30,"sourceCode":"\t\"github.com/rs/zerolog/log\"\n\t\"golang.org/x/term\"\n)\n\ntype GenerateCmd struct {\n\tUsername        string `arg:\"positional\"`\n\tPassword        string `arg:\"--password, -p\" help:\"sets the password for the user\"`\n\tName            string `arg:\"--name, -n\" help:\"sets the display name for the user\"`\n\tEmail           string `arg:\"--email, -e\" help:\"sets the email for the user\"`\n\tFilter          string `arg:\"--user-filter\" help:\"sets the filter for the user. This can be a comma separated list of filters.\"`\n\tRolesConfigured string `arg:\"--user-roles\" help:\"sets the roles for the user. This can be a comma separated list of roles.\"`\n}\n\nfunc (g *GenerateCmd) Run(args Args, embeddedCerts embed.FS) error {\n\twriter := zerolog.NewConsoleWriter()\n\tlog.Logger = log.Output(writer)\n\tStartEvent(args, \"\", nil, \"generate\")\n\tif args.Generate.Username == \"\" {\n\t\treturn fmt.Errorf(\"username is required\")\n\t}\n\n\tpassword := args.Generate.Password\n\tif password == \"\" {\n\t\tvar err error\n\t\tif password, err = readPassword(); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\tif password == \"\" {\n\t\treturn fmt.Errorf(\"password is required\")\n\t}\n\n\tbuffer := auth.GenerateUsers(auth.User{\n\t\tUsername:        args.Generate.Username,\n\t\tPassword:        password,\n\t\tName:            args.Generate.Name,\n\t\tEmail:           args.Generate.Email,","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/amir20/dozzle/blob/d9463cbe21874e44ab79db6fa63e746ca7d22928/internal/support/cli/generate_command.go#L12-L48","documentation":"Returned by GenerateCmd.Run when args.Generate.Username is empty. The generate command creates a user entry (for users.yml auth), and a username is mandatory, so it fails fast before prompting for a password.","triggerScenarios":"Running `dozzle generate` without the positional username argument; passing an empty string via automation; invoking the command with flags only and no positional value.","commonSituations":"Scripting user generation and forgetting the positional argument; interactive users pressing enter at the wrong prompt; copy-pasting an example command and dropping the username token.","solutions":["Pass a username: `dozzle generate --name \"Admin\" admin` (username is the positional arg).","Check the command help: `dozzle generate --help` for the expected argument order.","Fix automation scripts to interpolate a non-empty username variable.","If the username was meant to come from env/config, export and pass it explicitly."],"exampleFix":"// before\n./dozzle generate --password secret123\n// after\n./dozzle generate --password secret123 admin","handlingStrategy":"validation","validationCode":"[ -n \"$USERNAME\" ] || { echo 'username is required'; exit 1; }","typeGuard":null,"tryCatchPattern":"if err := generateCmd.Run(args, embeddedCerts); err != nil {\n  if strings.Contains(err.Error(), \"username is required\") {\n    log.Fatal().Msg(\"pass a positional username, e.g. dozzle generate admin\")\n  }\n}","preventionTips":["Always pass the username as the first positional argument","Guard scripts for empty username variables","Run `dozzle generate --help` to confirm argument order","Never rely on defaults for required auth fields"],"tags":["cli","validation","auth"],"backgroundTag":"missing-required-argument","analyzedSha":"d9463cbe21874e44ab79db6fa63e746ca7d22928","analyzedAt":"2026-09-07T10:08:55.855Z","contentChangedAt":"2026-09-07T10:08:55.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}