plandex-ai/plandex · error

invalid email: %v

Error message

invalid email: %v

What it means

CreateUser validates the email by splitting on '@' and requires exactly two parts (local and domain). Any email with zero or multiple '@' characters fails this check and returns this error before any DB work happens.

Source

Thrown at app/server/db/user_helpers.go:135

	userIds := make([]string, len(orgUsers))
	for i, ou := range orgUsers {
		userIds[i] = ou.UserId
	}

	err = Conn.Select(&users, "SELECT * FROM users WHERE id = ANY($1)", pq.Array(userIds))

	if err != nil {
		return nil, fmt.Errorf("error listing users: %v", err)
	}

	return users, nil
}

func CreateUser(name, email string, tx *sqlx.Tx) (*User, error) {
	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)
	}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Validate the email on the client/server request handler before calling CreateAccount/CreateUser
  2. Use a regex or net/mail.ParseAddress to check the format before insertion
  3. Decode and trim the incoming request body's Email field (handle %40, whitespace)
  4. Return a 400 to the user asking them to correct the email

Example fix

// before
db.CreateUser(name, "jane@example", tx) // no '@' → error
// after
addr, err := mail.ParseAddress(email)
if err != nil { return nil, errors.New("invalid email supplied") }
db.CreateUser(name, addr.Address, tx)
Defensive patterns

Strategy: validation

Validate before calling

func validEmail(email string) bool {
    return strings.Count(email, "@") == 1 && len(strings.Split(email, "@")[1]) > 0
}
// call CreateUser only if validEmail(email)

Try / catch

user, err := db.CreateUser(name, email, tx)
if err != nil {
    if strings.HasPrefix(err.Error(), "invalid email") { return http.StatusBadRequest }
    return http.StatusInternalServerError
}

Prevention

When it happens

Trigger: Calling CreateUser (via CreateAccount) with an email string that does not contain exactly one '@', e.g. empty string, 'userexample.com', or 'a@@b.com'.

Common situations: Sign-up form submitted without email validation, email field empty after trimming, or copying emails with encoded '@' (%40) not decoded.

Related errors


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