plandex-ai/plandex · error

error creating project: %v

Error message

error creating project: %v

What it means

CreateProjectHandler wraps project creation in a transaction via db.WithTx; db.CreateProject inserts the new project row for the org. If the insert fails, the tx is rolled back and the error is wrapped as 'error creating project', surfacing as an HTTP 500.

Source

Thrown at app/server/handlers/projects.go:55

		http.Error(w, "Error parsing request body", http.StatusBadRequest)
		return
	}

	if requestBody.Name == "" {
		log.Println("Received empty name field")
		http.Error(w, "name field is required", http.StatusBadRequest)
		return
	}

	var projectId string
	err = db.WithTx(r.Context(), "create project", func(tx *sqlx.Tx) error {
		var err error

		projectId, err = db.CreateProject(auth.OrgId, requestBody.Name, tx)

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

		return nil
	})

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

	resp := shared.CreateProjectResponse{
		Id: projectId,
	}

	bytes, err := json.Marshal(resp)

	if err != nil {

View on GitHub (pinned to e2d772072e)

Solutions

  1. Inspect the wrapped cause: duplicate key, FK violation, or connection issue.
  2. Check for an existing project with the same name in the org before creating.
  3. Retry on transient errors (deadlock, serialization) with backoff.
  4. Validate requestBody.Name is non-empty before the transaction.

Example fix

// before
projectId, err = db.CreateProject(auth.OrgId, requestBody.Name, tx)
// after
if strings.TrimSpace(requestBody.Name) == "" {
    return fmt.Errorf("project name is required")
}
projectId, err = db.CreateProject(auth.OrgId, requestBody.Name, tx)
Defensive patterns

Strategy: validation

Validate before calling

// Go
name := strings.TrimSpace(requestBody.Name)
if name == "" {
    http.Error(w, "project name is required", http.StatusBadRequest)
    return
}

Type guard

func projectNameValid(name string) bool { return strings.TrimSpace(name) != "" }

Try / catch

err := db.WithTx(ctx, "create project", func(tx *sqlx.Tx) error {
    projectId, err = db.CreateProject(auth.OrgId, name, tx)
    if err != nil {
        if isDuplicateKeyErr(err) {
            return errProjectExists
        }
        return fmt.Errorf("error creating project: %v", err)
    }
    return nil
})

Prevention

When it happens

Trigger: db.CreateProject fails: duplicate project name where uniqueness is enforced, FK violation on org_id, transaction deadlock or serialization failure, DB connection loss mid-tx, or empty request body Name.

Common situations: Duplicate-name race between two concurrent project creations; org row deleted elsewhere; Postgres deadlocks under load; DB not migrated.

Related errors


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