plandex-ai/plandex · error
error creating user: %v
Error message
error creating user: %v
What it means
Generic insertion-failure branch in CreateUser: any INSERT error that is not a unique-constraint violation (per IsNonUniqueErr) is wrapped with this message. It represents an unexpected database failure while creating the user row.
Source
Thrown at app/server/db/user_helpers.go:151
emailSplit := strings.Split(email, "@")
if len(emailSplit) != 2 {
return nil, fmt.Errorf("invalid email: %v", email)
}
domain := emailSplit[1]
user := User{
Name: name,
Email: email,
Domain: domain,
}
err := tx.QueryRow("INSERT INTO users (name, email, domain) VALUES ($1, $2, $3) RETURNING id", user.Name, user.Email, user.Domain).Scan(&user.Id)
if err != nil {
if IsNonUniqueErr(err) {
return nil, fmt.Errorf("user already exists for email: %v", email)
}
return nil, fmt.Errorf("error creating user: %v", err)
}
return &user, nil
}
func NumUsersWithRole(orgId, roleId string) (int, error) {
var count int
err := Conn.Get(&count, "SELECT COUNT(*) FROM orgs_users WHERE org_id = $1 AND org_role_id = $2", orgId, roleId)
if err != nil {
return 0, fmt.Errorf("error counting users with role: %v", err)
}
return count, nil
}
View on GitHub (pinned to e2d772072e)
Solutions
- Log the wrapped underlying error (%v of err) to see the actual pq driver failure
- Verify the users table schema matches the INSERT (run pending migrations)
- Check DB connectivity and that the transaction passed to CreateUser is still valid/alive
- Confirm which constraint failed — a non-email unique index still lands in this branch
- Retry the request if the failure was transient (connection blip)
Example fix
// before
return nil, fmt.Errorf("error creating user: %v", err)
// after
return nil, fmt.Errorf("error creating user: %w", err) // enables errors.Is/As on the pq.Error Defensive patterns
Strategy: try-catch
Try / catch
user, err := db.CreateUser(name, email, tx)
if err != nil {
if strings.HasPrefix(err.Error(), "error creating user") {
log.Printf("user insert failed: %v", err) // inspect wrapped pq error
return http.StatusBadGateway // or retry if transient
}
} Prevention
- Keep migrations applied so the users table schema matches the INSERT
- Use %w wrapping (and errors.As with *pq.Error) to classify failures
- Ensure the sqlx.Tx is alive and not already aborted before calling
- Alert on elevated rates of this error — usually infra/schema, not user input
When it happens
Trigger: The INSERT INTO users statement fails for non-duplicate reasons: connection failure, schema mismatch (missing column), constraint violation other than email uniqueness, or transaction already aborted inside the WithTx block in CreateAccount.
Common situations: DB migrations not applied (columns missing), database unreachable during deploy, transaction rolled back earlier leaving the tx in an aborted state, or a different unique index (e.g. domain) being violated.
Related errors
- Error archiving plan:
- Error deleting auth token:
- Error getting org user config:
- error invalidating conflicted results: %v
- error adding plan context tokens: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/b09ab92ee7981f91.
Report an issue: GitHub.