{"record":{"id":"2e7d23f2d92208da","repo":"AdguardTeam/AdGuardHome","slug":"searching-user-by-login-q-w","errorCode":null,"errorMessage":"searching user by login %q: %w","messagePattern":"searching user by login %q: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"internal/home/authhttp.go","lineNumber":537,"sourceCode":") (u *aghuser.User, err error) {\n\tt, err := sessionTokenFromHex(val)\n\tif err != nil {\n\t\t// Don't wrap the error because it's informative enough as is.\n\t\treturn nil, err\n\t}\n\n\ts, err := mw.sessions.FindByToken(ctx, t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"searching session by token: %w\", err)\n\t}\n\n\tif s == nil {\n\t\treturn nil, nil\n\t}\n\n\tu, err = mw.users.ByLogin(ctx, s.UserLogin)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"searching user by login %q: %w\", s.UserLogin, err)\n\t}\n\n\treturn u, nil\n}\n\n// sessionTokenFromHex converts a hexadecimal string into a session token.\nfunc sessionTokenFromHex(val string) (token aghuser.SessionToken, err error) {\n\tsess, err := hex.DecodeString(val)\n\tif err != nil {\n\t\treturn token, fmt.Errorf(\"decoding value: %w\", err)\n\t}\n\n\tl := aghuser.SessionTokenLength\n\n\terr = validate.Equal(\"token length\", l, len(sess))\n\tif err != nil {\n\t\t// Don't wrap the error because it's informative enough as is.\n\t\treturn token, err","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/home/authhttp.go#L519-L555","documentation":"A session cookie resolved to a valid session, but loading the user by login from the users storage failed. The wrapped error indicates the user store (JSON/DB) backend error, not a missing user.","triggerScenarios":"userFromCookie with a session whose s.UserLogin lookup via Users.ByLogin returns an error (I/O, parse, or consistency failure).","commonSituations":"Users file corrupted or being rewritten concurrently, schema mismatch after downgrade, permission issues on data dir.","solutions":["Inspect the wrapped error to identify the storage failure","Check/repair the users storage file in the working directory","Ensure single instance and correct file permissions","As a last resort, recreate the users store (users will need re-provisioning)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// On user-store errors, force re-login rather than retrying\nif err != nil { clearSessionCookie(w); redirect to login }","preventionTips":["Keep the users storage file consistent and backed up","Pin API/tool versions matching the server build"],"tags":["auth","user-store","storage","middleware"],"backgroundTag":"user-lookup-failure","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}