plandex-ai/plandex · error
error deleting plans: %v
Error message
error deleting plans: %v
What it means
DeleteOwnerPlans deletes ALL plans owned by a user in a project (not just drafts) and collects their ids via RETURNING. This error wraps a failure of the DELETE query itself, meaning the database could not execute the statement.
Source
Thrown at app/server/db/plan_helpers.go:403
for i := 0; i < len(ids); i++ {
err := <-errCh
if err != nil {
return fmt.Errorf("error deleting draft plan dir: %v", err)
}
}
if len(ids) > 0 {
log.Println("Deleted", len(ids), "draft plans")
}
return nil
}
func DeleteOwnerPlans(orgId, projectId, userId string) error {
res, err := Conn.Query("DELETE FROM plans WHERE project_id = $1 AND owner_id = $2 RETURNING id;", projectId, userId)
if err != nil {
return fmt.Errorf("error deleting 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)
Solutions
- Check the wrapped driver error for the exact cause
- Verify the app's DB role has DELETE privilege on plans
- Confirm schema contains project_id/owner_id columns (run migrations)
- Check connection pool health and timeouts
Example fix
// before
if err != nil {
return fmt.Errorf("error deleting plans: %v", err)
}
// after
if err != nil {
return fmt.Errorf("error deleting plans: %w", err)
} Defensive patterns
Strategy: retry
Validate before calling
var hasDelete bool
err := db.Get(&hasDelete, "SELECT has_table_privilege('plans', 'DELETE')")
if err != nil || !hasDelete {
return fmt.Errorf("app role lacks DELETE on plans")
} Try / catch
if err := DeleteOwnerPlans(orgId, projectId, userId); err != nil {
var pqErr *pq.Error
if errors.As(err, &pqErr) && pqErr.Code == "42501" {
// permission denied: grant DELETE or fix role
}
return err
} Prevention
- Grant the app DB role DELETE on plans in migration scripts
- Run migrations before deploy
- Retry on driver.ErrBadConn and net errors
- Monitor DB connectivity and pool limits
When it happens
Trigger: Conn.Query("DELETE FROM plans WHERE project_id = $1 AND owner_id = $2 RETURNING id;", ...) fails: dead DB connection, schema mismatch, permission denied on the plans table for the app's DB role, or statement timeout.
Common situations: DB role lacking DELETE privilege after a security hardening change; connection pool exhaustion; migration drift removing the owner_id column; network partition between app and Postgres.
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
- error deleting draft plans: %v
- error deleting invite: %v
- error removing all locks: %v
- error creating plan: %v
- error inserting lockable plan id: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/93afee49c6ed0e3c.
Report an issue: GitHub.