apache/answer · error
query user failed: %w
Error message
query user failed: %w
What it means
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'.
Source
Thrown at internal/cli/reset_password.go:115
userRepo := user.NewUserRepo(dataData)
authRepo := auth.NewAuthRepo(dataData)
apiKeyRepo := api_key.NewAPIKeyRepo(dataData)
authSvc := authService.NewAuthService(authRepo, apiKeyRepo)
email := strings.TrimSpace(opts.Email)
if email == "" {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Please input user email: ")
emailInput, err := reader.ReadString('\n')
if err != nil {
return fmt.Errorf("read email input failed: %w", err)
}
email = strings.TrimSpace(emailInput)
}
userInfo, exist, err := userRepo.GetByEmail(ctx, email)
if err != nil {
return fmt.Errorf("query user failed: %w", err)
}
if !exist {
return fmt.Errorf("user not found: %s", email)
}
fmt.Printf("You are going to reset password for user: %s\n", email)
password := strings.TrimSpace(opts.Password)
if password != "" {
printWarning("Passing password via command line may be recorded in shell history")
if err := checker.CheckPassword(password); err != nil {
return fmt.Errorf("password validation failed: %w", err)
}
} else {
password, err = promptForPassword()
if err != nil {
return fmt.Errorf("password input failed: %w", err)View on GitHub (pinned to 3b9f137061)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
if err := db.Ping(); err != nil { return fmt.Errorf("db down: %w", err) }
// ensure migrations applied so users table exists Try / catch
if err := cli.ResetPassword(ctx, dataDir, opts); err != nil {
if strings.Contains(err.Error(), "query user failed") {
log.Fatalf("DB query failed; check migrations and server health: %v", err)
}
} Prevention
- Apply DB migrations before user lookups
- Set sane query timeouts and retry on transient errors
- Alert on DB server restarts/corruption
When it happens
Trigger: userRepo.GetByEmail executes a query that errors — DB connection dropped mid-session, users table missing/corrupt, query timeout, SQL syntax/driver mismatch.
Common situations: Database schema not migrated (missing users/auth tables), connection pooled but server restarted, DB under heavy load causing timeouts.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- get config failed: %w
- update site info failed: %w
- update plugin status failed: %w
- connect database failed: %w
- initialize data layer failed: %w
AI-assisted analysis of apache/answer@3b9f137061 (2026-09-05).
Data as JSON: /api/errors/8bcb30f8de24fe83.
Report an issue: GitHub.