{"record":{"id":"6e1d282334d02b7d","repo":"AlistGo/alist","slug":"username-is-empty","errorCode":null,"errorMessage":"username is empty","messagePattern":"username is empty","errorType":"exception","errorClass":"EmptyUsername","httpStatus":null,"severity":"warning","filePath":"internal/errs/user.go","lineNumber":6,"sourceCode":"package errs\n\nimport \"errors\"\n\nvar (\n\tEmptyUsername      = errors.New(\"username is empty\")\n\tEmptyPassword      = errors.New(\"password is empty\")\n\tWrongPassword      = errors.New(\"password is incorrect\")\n\tDeleteAdminOrGuest = errors.New(\"cannot delete admin or guest\")\n)\n","sourceCodeStart":1,"sourceCodeEnd":11,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/internal/errs/user.go#L1-L11","documentation":"EmptyUsername is a sentinel in internal/errs/user.go raised during user validation when a request that requires a username supplies an empty one. It guards user creation/update in the admin API and the login flow before any credential check happens.","triggerScenarios":"POSTing a login request with an empty/missing username field; creating or updating a user via the admin API without a username; whitespace-only username that survives trimming checks.","commonSituations":"Forms with a missing username input; API scripts sending {\"username\":\"\"} or omitting the key; automation generating users from unpopulated template variables; proxied requests where the field is dropped by a misconfigured body limit or middleware.","solutions":["Ensure the username field is non-empty before submitting (client-side required check)","Inspect the actual JSON body sent — the key must be exactly 'username'","Trim input and reject empty strings before calling the user API","If scripting, validate generated usernames are populated before the request"],"exampleFix":"// before\nif username == \"\" { /* nothing, request fails server-side */ }\n\n// after\nif strings.TrimSpace(username) == \"\" {\n    return errs.EmptyUsername\n}","handlingStrategy":"validation","validationCode":"// client-side guard before login/user APIs\nif strings.TrimSpace(username) == \"\" {\n    return errs.EmptyUsername\n}","typeGuard":"func hasUsername(s string) bool { return strings.TrimSpace(s) != \"\" }","tryCatchPattern":"if err := login(user, pass); err != nil {\n    if errors.Is(err, errs.EmptyUsername) { /* prompt for username */ }\n}","preventionTips":["Make the username field required in forms","Validate generated usernames in scripts are non-empty","Send the exact JSON key 'username'","Trim and reject whitespace-only input client-side"],"tags":["auth","user","validation"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}