plandex-ai/plandex · error

error creating org: %v

Error message

error creating org: %v

What it means

Wrapped error from the create-org transaction when db.CreateOrg fails to insert the new org row. The WithTx closure returns this error, the transaction rolls back, and the handler responds 500 'Error creating org'.

Source

Thrown at app/server/handlers/orgs.go:107

	var org *db.Org
	err = db.WithTx(r.Context(), "create org", func(tx *sqlx.Tx) error {
		var err error
		var domain *string
		if req.AutoAddDomainUsers {
			if shared.IsEmailServiceDomain(auth.User.Domain) {
				log.Printf("Invalid domain: %v\n", auth.User.Domain)
				return fmt.Errorf("invalid domain: %v", auth.User.Domain)
			}

			domain = &auth.User.Domain
		}

		// create a new org
		org, err = db.CreateOrg(&req, auth.AuthToken.UserId, domain, tx)

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

		if org.AutoAddDomainUsers && org.Domain != nil {
			err = db.AddOrgDomainUsers(org.Id, *org.Domain, tx)

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

		_, apiErr = hooks.ExecHook(hooks.CreateOrg, hooks.HookParams{
			Auth: auth,
			Tx:   tx,

			CreateOrgHookRequestParams: &hooks.CreateOrgHookRequestParams{
				Org: org,
			},

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check server logs for the wrapped %v error to see the exact Postgres failure (constraint, connection)
  2. Retry with a different org name/domain if a unique constraint fired
  3. Verify DB connectivity and schema migrations if the error is connection- or column-related
  4. Consider returning 409 for duplicate org/domain instead of 500

Example fix

// before: duplicate domain
client.CreateOrg(shared.CreateOrgRequest{Name: "acme", Domain: "acme.com"})
// after: unique name/domain or omit domain
client.CreateOrg(shared.CreateOrgRequest{Name: "acme-2"})
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-flight: pick a unique name; send a domain only if you own it
if (!req.name || req.name.trim() === '') throw new Error('org name required')

Try / catch

try {
  org = await client.CreateOrg(req)
} catch (err) {
  if (String(err.message).includes('error creating org')) {
    // unique-constraint or DB failure: change name/domain and retry once
    req.name = req.name + '-' + Date.now()
    org = await client.CreateOrg(req)
  }
}

Prevention

When it happens

Trigger: POST to create-org where db.CreateOrg(&req, userId, domain, tx) hits a DB error: unique constraint on org name/domain, invalid or conflicting domain value, connection failure, or tx already aborted by an earlier step in the closure.

Common situations: Creating an org with a domain another org already claims; DB pool exhaustion; migration drift so the insert references a missing column.

Related errors


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