plandex-ai/plandex · error

error deleting draft plans

Error message

error deleting draft plans: %v

What it means

DeleteDraftPlans removes all plans named 'draft' for a project+owner and returns their ids. This error wraps a failure of the DELETE ... RETURNING query itself, meaning the database refused or could not execute the statement (connection issue, SQL error).

Solutions

  1. Check the wrapped driver error for the exact Postgres failure
  2. Verify DB connectivity and connection-pool limits
  3. Confirm schema migrations ran (plans table, project_id/owner_id columns exist)
  4. Enable driver-level retry/reconnect on transient connection errors

Example fix

// before
if err != nil {
    return fmt.Errorf("error deleting draft plans: %v", err)
}
// after
if err != nil {
    return fmt.Errorf("error deleting draft plans: %w", err)
}
Defensive patterns

Strategy: retry

Validate before calling

if err := db.PingContext(ctx); err != nil {
    return fmt.Errorf("database unreachable: %w", err)
}

Try / catch

err := DeleteDraftPlans(orgId, projectId, userId)
if err != nil {
    if isTransientDBError(err) { // net.Error, driver.ErrBadConn
        err = retry(3, func() error { return DeleteDraftPlans(orgId, projectId, userId) })
    }
    return err
}

Prevention

When it happens

Trigger: Conn.Query("DELETE FROM plans WHERE project_id = $1 AND owner_id = $2 AND name = 'draft' RETURNING id;", ...) fails: connection to Postgres dropped, table missing after migration drift, syntax/type mismatch, or DB timeout.

Common situations: DB connection pool exhausted; schema migration out of sync (plans table or columns missing); network blip between app and database; using a closed global Conn after failed reconnect.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


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

Appendix: source

Thrown at app/server/db/plan_helpers.go:355

	bytes, err := json.Marshal(description)

	if err != nil {
		return fmt.Errorf("error marshalling convo message description: %v", err)
	}

	err = os.WriteFile(filepath.Join(descriptionsDir, description.Id+".json"), bytes, os.ModePerm)

	if err != nil {
		return fmt.Errorf("error writing convo message description: %v", err)
	}

	return nil
}

func DeleteDraftPlans(orgId, projectId, userId string) error {
	res, err := Conn.Query("DELETE FROM plans WHERE project_id = $1 AND owner_id = $2 AND name = 'draft' RETURNING id;", projectId, userId)
	if err != nil {
		return fmt.Errorf("error deleting draft plans: %v", err)
	}

	defer res.Close()

	// get ids
	var ids []string

	for res.Next() {
		var id string
		err := res.Scan(&id)
		if err != nil {
			return fmt.Errorf("error scanning deleted draft plan id: %v", err)
		}
		ids = append(ids, id)
	}

	errCh := make(chan error, len(ids))
	for _, planId := range ids {

View on GitHub (pinned to e2d772072e)