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

  1. Log the wrapped underlying error (%v of err) to see the actual pq driver failure
  2. Verify the users table schema matches the INSERT (run pending migrations)
  3. Check DB connectivity and that the transaction passed to CreateUser is still valid/alive
  4. Confirm which constraint failed — a non-email unique index still lands in this branch
  5. 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

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


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/b09ab92ee7981f91. Report an issue: GitHub.