carlos / platform Public

console: tell the ops-account refusal apart with a sentinel

deletionAdvice picked "The ops account is the platform's own and
cannot be deleted" for any DeleteAccount error whose text held "ops",
so a store failure naming, say, a workshops table told an owner their
account was the platform's. DeleteAccount now returns
errOpsAccountUndeletable (same message as before), deletionRefused
passes that sentinel, and deletionAdvice matches it with errors.Is.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev e4f908d37c91fa66b4386ddd713ef75062adffb4 parent 24ff6c9
2 files changed, +34 −3
  • internal/console/ownership.go +8 −3
  • internal/console/store_test.go +26 −0

CI cancelled — superseded by a newer push — run details

diff --git a/internal/console/ownership.go b/internal/console/ownership.go
index 6157b416d..09a060570 100644
--- a/internal/console/ownership.go
+++ b/internal/console/ownership.go
@@ -160,7 +160,7 @@ func (s *Server) handleDeleteAccount(w http.ResponseWriter, r *http.Request) {
// act on by dropping its registry row.
func (s *Server) deletionRefused(w http.ResponseWriter, r *http.Request, acct *Account) bool {
if acct.ID == OpsAccountID {
- s.setFlash(w, "err", deletionAdvice(fmt.Errorf("console: ops")))
+ s.setFlash(w, "err", deletionAdvice(errOpsAccountUndeletable))
http.Redirect(w, r, "/a/"+acct.Sqid+"/settings", http.StatusSeeOther)
return true
}
@@ -718,12 +718,17 @@ func deletionAdvice(err error) string {
return "This account still holds apps. Move or retire them first — deleting an account " +
"never deletes an app."
}
- if strings.Contains(err.Error(), "ops") {
+ if errors.Is(err, errOpsAccountUndeletable) {
return "The ops account is the platform's own and cannot be deleted."
}
return "Could not delete this account."
}
+// errOpsAccountUndeletable is DeleteAccount's refusal of the ops account.
+// deletionAdvice matches it with errors.Is: matching "ops" in the message
+// also matched any store error that happened to contain those letters.
+var errOpsAccountUndeletable = errors.New("console: the ops account cannot be deleted")
+
// ---- store ------------------------------------------------------------------
// TransferOwnership promotes `to` and demotes `from`, atomically. Both must
@@ -784,7 +789,7 @@ func (s *Store) TransferOwnership(accountID int64, from, to string, now time.Tim
// done, and a deletion is not a reason to lose it.
func (s *Store) DeleteAccount(accountID int64, now time.Time) error {
if accountID == OpsAccountID {
- return fmt.Errorf("console: the ops account cannot be deleted")
+ return errOpsAccountUndeletable
}
tx, err := s.db.Begin()
if err != nil {
diff --git a/internal/console/store_test.go b/internal/console/store_test.go
index afac6ef3f..38d36bd80 100644
--- a/internal/console/store_test.go
+++ b/internal/console/store_test.go
@@ -1,6 +1,8 @@
package console
import (
+ "errors"
+ "fmt"
"path/filepath"
"reflect"
"sort"
@@ -641,6 +643,30 @@ func TestDeleteAccountRefusesOps(t *testing.T) {
}
}
+// TestDeletionAdviceNamesOpsOnlyForTheOpsRefusal: the ops-account advice is
+// given for DeleteAccount's ops refusal, wrapped or not, and for nothing else.
+// It used to be chosen by finding "ops" anywhere in the error text, so a
+// store failure such as one naming a "workshops" table told the owner their
+// account was the platform's own.
+func TestDeletionAdviceNamesOpsOnlyForTheOpsRefusal(t *testing.T) {
+ const opsAdvice = "The ops account is the platform's own and cannot be deleted."
+ s := openTestStore(t)
+ refusal := s.DeleteAccount(OpsAccountID, time.Now())
+ for _, err := range []error{refusal, fmt.Errorf("delete: %w", refusal)} {
+ if got := deletionAdvice(err); got != opsAdvice {
+ t.Fatalf("deletionAdvice(%v) = %q, want the ops advice", err, got)
+ }
+ }
+ for _, err := range []error{
+ errors.New("no such table: workshops"),
+ errors.New("database is locked; ops retried"),
+ } {
+ if got := deletionAdvice(err); got != "Could not delete this account." {
+ t.Fatalf("deletionAdvice(%v) = %q, want the generic advice", err, got)
+ }
+ }
+}
+
// TestReapAccountClearsAndMarks: materialization's verb for a manifest
// tombstoned on a LATER pass — memberships, invites and apps rows are
// deleted outright, last_account references are cleared, and the accounts