plandex-ai/plandex · error

Error deleting org user: {err.Error()}

Error message

Error deleting org user: {err.Error()}

What it means

The db.WithTx transaction wrapping the delete failed: DeleteOrgUser, GetActiveInviteByEmail, or DeleteInvite returned an error inside the callback, or the transaction itself (commit/rollback/context) failed. The handler replies HTTP 500 'Error deleting org user: <err>' and the tx is rolled back, so no partial deletion persists.

Source

Thrown at app/server/handlers/users.go:218

			log.Println("Error getting invite for org user: ", err)
			return fmt.Errorf("error getting invite for org user: %v", err)
		}

		if invite != nil {
			err = db.DeleteInvite(invite.Id, tx)

			if err != nil {
				log.Println("Error deleting invite: ", err)
				return fmt.Errorf("error deleting invite: %v", err)
			}
		}

		return nil
	})

	if err != nil {
		log.Println("Error deleting org user: ", err)
		http.Error(w, "Error deleting org user: "+err.Error(), http.StatusInternalServerError)
		return
	}

	log.Println("Successfully processed request for DeleteOrgUserHandler")
}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Read the server log 'Error deleting org user: ' to see which inner step failed
  2. Resolve FK constraints blocking DeleteOrgUser (delete or reassign dependent rows first)
  3. Verify GetActiveInviteByEmail handles no-invite cases as nil rather than erroring
  4. Increase client timeout / avoid cancelling requests mid-tx; retry once the DB is healthy

Example fix

// before
invite, err := db.GetActiveInviteByEmail(auth.OrgId, auth.User.Email)
if err != nil {
    return fmt.Errorf("error getting invite for org user: %v", err)
}
// after
invite, err := db.GetActiveInviteByEmail(auth.OrgId, auth.User.Email)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
    return fmt.Errorf("error getting invite for org user: %v", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
defer cancel()
if err := db.PingContext(ctx); err != nil {
    return fmt.Errorf("db unavailable: %w", err)
}

Try / catch

err = db.WithTx(r.Context(), "delete org user", func(tx *sqlx.Tx) error {
    if err := db.DeleteOrgUser(auth.OrgId, userId, tx); err != nil {
        return fmt.Errorf("delete org user: %w", err)
    }
    return nil
})
if err != nil {
    log.Printf("delete org user tx failed: %v", err) // tx already rolled back
    http.Error(w, "internal error", http.StatusInternalServerError)
    return
}

Prevention

When it happens

Trigger: Any step inside the 'delete org user' transaction errors: the org_users DELETE fails (FK constraints, row gone), the active-invite lookup errors, invite deletion fails, or the tx context is cancelled (client disconnect/timeout).

Common situations: Foreign-key rows referencing the org_user block deletion; client timeout cancels r.Context() mid-tx; DB connection drop between statements; GetActiveInviteByEmail returning an unexpected error for users with no invites if the query treats 'none' as an error.

Related errors


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