plandex-ai/plandex · error

Error inviting user:

Error message

Error inviting user: 

What it means

InviteUserHandler wraps any error returned by the db.WithTx('invite user', ...) transaction into an HTTP 500 prefixed with 'Error inviting user: '. The transaction does two things: db.CreateInvite and email.SendInviteEmail; if either fails, the tx returns an error and the invite row is rolled back. The wrapped message distinguishes 'error creating invite: ...' from 'error sending invite email: ...' inside err.Error().

Source

Thrown at app/server/handlers/invites.go:155

		if err != nil {
			log.Printf("Error creating invite: %v\n", err)
			return fmt.Errorf("error creating invite: %v", err)
		}

		err = email.SendInviteEmail(req.Email, req.Name, auth.User.Name, org.Name)

		if err != nil {
			log.Printf("Error sending invite email: %v\n", err)
			return fmt.Errorf("error sending invite email: %v", err)
		}

		return nil
	})

	if err != nil {
		log.Printf("Error inviting user: %v\n", err)
		http.Error(w, "Error inviting user: "+err.Error(), http.StatusInternalServerError)
		return
	}

	log.Println("Successfully created invite")
}

func ListPendingInvitesHandler(w http.ResponseWriter, r *http.Request) {
	log.Println("Received a request for ListInvitesHandler")

	if os.Getenv("GOENV") == "development" && os.Getenv("LOCAL_MODE") == "1" {
		writeApiError(w, shared.ApiError{
			Type:   shared.ApiErrorTypeOther,
			Status: http.StatusForbidden,
			Msg:    "Local mode is not supported for invites",
		})
		return
	}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Inspect err.Error() in the response/log to see whether it says 'creating invite' or 'sending invite email'
  2. If it's the email step: verify SMTP/email provider env vars and credentials, test the provider from the host, check rate limits and recipient validity
  3. If it's the create step: check for concurrent duplicate invites or DB connectivity problems
  4. Retry after fixing; the transaction rolls back so no partial invite row remains
  5. Consider decoupling email sending from the invite transaction so email failures don't invalidate the invite

Example fix

// before
err = email.SendInviteEmail(req.Email, req.Name, auth.User.Name, org.Name)
if err != nil {
    return fmt.Errorf("error sending invite email: %v", err)
}
// after
err = email.SendInviteEmail(req.Email, req.Name, auth.User.Name, org.Name)
if err != nil {
    log.Printf("invite persisted but email send failed: %v\n", err)
    return nil // invite row kept; retry email out-of-band
}
Defensive patterns

Strategy: try-catch

Validate before calling

// client: nothing to pre-validate for SMTP; server-side, verify email config at startup
if os.Getenv("SMTP_HOST") == "" || os.Getenv("SMTP_FROM") == "" {
    log.Fatal("email/SMTP env vars must be set before accepting invites")
}

Type guard

func isEmailSendFailure(errMsg string) bool {
    return strings.Contains(errMsg, "error sending invite email")
}
func isCreateInviteFailure(errMsg string) bool {
    return strings.Contains(errMsg, "error creating invite")
}

Try / catch

resp, err := client.Post(inviteUrl, jsonBody)
body, _ := io.ReadAll(resp.Body)
if resp.StatusCode == 500 && strings.Contains(string(body), "Error inviting user") {
    if strings.Contains(string(body), "sending invite email") {
        return fmt.Errorf("invite email failed (check SMTP config); retry later: %s", body)
    }
    return fmt.Errorf("invite creation failed; safe to retry: %s", body)
}

Prevention

When it happens

Trigger: POST to the invite-user endpoint where the CreateInvite INSERT fails (constraint violation, DB down) or SendInviteEmail fails (SMTP misconfigured, bad credentials, unreachable mail provider, rejected recipient address).

Common situations: Email/SMTP env vars (provider API key, host, from-address) missing or wrong in the deployment; mail provider rate limits or bounced addresses; duplicate invite inserted concurrently by two admins causing a unique constraint failure; Postgres outage during the transaction.

Related errors


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