plandex-ai/plandex · error

error creating project: %v

Error message

error creating project: %v

What it means

CreateProject inserts a row into projects and scans the RETURNING id from the provided transaction (tx.QueryRow). Any insert failure — constraint violation, transaction already aborted, unique name conflict — is wrapped with this message and returned with an empty projectId.

Source

Thrown at app/server/db/project_helpers.go:25

)

func ProjectExists(orgId, projectId string) (bool, error) {
	var count int
	err := Conn.QueryRow("SELECT COUNT(*) FROM projects WHERE org_id = $1 AND id = $2", orgId, projectId).Scan(&count)

	if err != nil {
		return false, fmt.Errorf("error checking if project exists: %v", err)
	}

	return count > 0, nil
}

func CreateProject(orgId, name string, tx *sqlx.Tx) (string, error) {
	var projectId string
	err := tx.QueryRow("INSERT INTO projects (org_id, name) VALUES ($1, $2) RETURNING id", orgId, name).Scan(&projectId)

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

	return projectId, nil
}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Inspect the wrapped inner error for the constraint or abort cause
  2. Verify orgId exists and name is non-empty and within length limits
  3. Check whether the tx was already aborted by a prior statement — if so fix that earlier error
  4. Add a unique-check or ON CONFLICT handling if duplicate names are the issue

Example fix

// before
tx.QueryRow("INSERT INTO projects (org_id, name) VALUES ($1, $2) RETURNING id", orgId, name)
// after
if name == "" {
    return "", fmt.Errorf("project name is required")
}
tx.QueryRow("INSERT INTO projects (org_id, name) VALUES ($1, $2) RETURNING id", orgId, name)
Defensive patterns

Strategy: try-catch

Validate before calling

if orgId == "" || strings.TrimSpace(name) == "" {
    return errors.New("orgId and non-empty name are required")
}

Try / catch

projectId, err := CreateProject(orgId, name, tx)
if err != nil {
    tx.Rollback()
    if strings.Contains(err.Error(), "duplicate key") {
        return ErrProjectNameTaken
    }
    return fmt.Errorf("project creation failed: %w", err)
}

Prevention

When it happens

Trigger: tx.QueryRow("INSERT INTO projects ... RETURNING id").Scan fails — e.g. a CHECK/NOT NULL/FK constraint on org_id or name, a duplicate project name if a unique index exists, or the surrounding transaction was previously aborted by an earlier error in the same tx.

Common situations: Creating a project with an empty or too-long name, an invalid orgId (FK violation), or reusing a tx after a prior statement in it failed (PostgreSQL aborted transaction).

Related errors


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