{"record":{"id":"8bcb30f8de24fe83","repo":"apache/answer","slug":"query-user-failed-w","errorCode":null,"errorMessage":"query user failed: %w","messagePattern":"query user failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cli/reset_password.go","lineNumber":115,"sourceCode":"\tuserRepo := user.NewUserRepo(dataData)\n\tauthRepo := auth.NewAuthRepo(dataData)\n\tapiKeyRepo := api_key.NewAPIKeyRepo(dataData)\n\tauthSvc := authService.NewAuthService(authRepo, apiKeyRepo)\n\n\temail := strings.TrimSpace(opts.Email)\n\tif email == \"\" {\n\t\treader := bufio.NewReader(os.Stdin)\n\t\tfmt.Print(\"Please input user email: \")\n\t\temailInput, err := reader.ReadString('\\n')\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"read email input failed: %w\", err)\n\t\t}\n\t\temail = strings.TrimSpace(emailInput)\n\t}\n\n\tuserInfo, exist, err := userRepo.GetByEmail(ctx, email)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"query user failed: %w\", err)\n\t}\n\tif !exist {\n\t\treturn fmt.Errorf(\"user not found: %s\", email)\n\t}\n\n\tfmt.Printf(\"You are going to reset password for user: %s\\n\", email)\n\n\tpassword := strings.TrimSpace(opts.Password)\n\n\tif password != \"\" {\n\t\tprintWarning(\"Passing password via command line may be recorded in shell history\")\n\t\tif err := checker.CheckPassword(password); err != nil {\n\t\t\treturn fmt.Errorf(\"password validation failed: %w\", err)\n\t\t}\n\t} else {\n\t\tpassword, err = promptForPassword()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"password input failed: %w\", err)","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/cli/reset_password.go#L97-L133","documentation":"Fires in ResetPassword when userRepo.GetByEmail returns a database error while looking up the user by the supplied or prompted email. This is a storage/query failure (connection loss, SQL error, table missing), not an 'absent user' case — that is reported separately as 'user not found'.","triggerScenarios":"userRepo.GetByEmail executes a query that errors — DB connection dropped mid-session, users table missing/corrupt, query timeout, SQL syntax/driver mismatch.","commonSituations":"Database schema not migrated (missing users/auth tables), connection pooled but server restarted, DB under heavy load causing timeouts.","solutions":["Verify DB connectivity and that required tables exist (run migrations).","Inspect the wrapped driver error for the root cause.","Check DB server logs for errors around the time of the lookup."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if err := db.Ping(); err != nil { return fmt.Errorf(\"db down: %w\", err) }\n// ensure migrations applied so users table exists","typeGuard":null,"tryCatchPattern":"if err := cli.ResetPassword(ctx, dataDir, opts); err != nil {\n    if strings.Contains(err.Error(), \"query user failed\") {\n        log.Fatalf(\"DB query failed; check migrations and server health: %v\", err)\n    }\n}","preventionTips":["Apply DB migrations before user lookups","Set sane query timeouts and retry on transient errors","Alert on DB server restarts/corruption"],"tags":["database","query","user"],"backgroundTag":"database-query-failed","analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}