aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/undo.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-10-05 17:39:06 -0400
committerhistoria <[not public]>2026-10-05 17:39:06 -0400
commitec703a39738fefb60817f5659f76f8e683f8d301 (patch)
tree00d1242d9f94bc2fec48331d8c02909be6b37f7a /internal/admin/undo.go
parent516fd29da423432ef6dfded21a984f1d15dcab1a (diff)
downloadthehouseoficarus-ec703a39738fefb60817f5659f76f8e683f8d301.tar.gz
fix: admin undo/redo failure, video poker cabinet ids, room ref behavior
Diffstat (limited to 'internal/admin/undo.go')
-rw-r--r--internal/admin/undo.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/internal/admin/undo.go b/internal/admin/undo.go
index 5683f13..c3231e3 100644
--- a/internal/admin/undo.go
+++ b/internal/admin/undo.go
@@ -85,6 +85,10 @@ type UndoStack struct {
// writes those files directly, so it must refuse the same files the raw
// file editor refuses. Optional; nil disables the refusal.
playerFileOnlineCheck func(relPath string) bool
+ // lastErr records the most recent Undo/Redo failure so the HTTP handler
+ // can distinguish a genuine failure from an empty history (both return a
+ // nil change). Owner-task access only.
+ lastErr error
}
func NewUndoStack(dataDir string) *UndoStack {
@@ -179,8 +183,10 @@ func (us *UndoStack) Undo() *ChangeDesc {
if err := us.applyUndo(last); err != nil {
log.Printf("undo: failed %s: %v", last.ShortDesc(), err)
+ us.lastErr = err
return nil
}
+ us.lastErr = nil
// Runtime migration moves with the file images: undo applies the
// inverse room-ID map so players, Hub membership, and casino room keys
// return to the old location together.
@@ -209,8 +215,10 @@ func (us *UndoStack) Redo() *ChangeDesc {
if err := us.applyRedo(last); err != nil {
log.Printf("redo: failed %s: %v", last.ShortDesc(), err)
+ us.lastErr = err
return nil
}
+ us.lastErr = nil
// Redo applies the forward room-ID map through the runtime migration.
if len(last.IDMap) > 0 && us.migrateRoomIDs != nil {
forward := make(map[int]int, len(last.IDMap))
@@ -803,6 +811,15 @@ func (us *UndoStack) Clear() {
defer us.mu.Unlock()
us.history = nil
us.redo = nil
+ us.lastErr = nil
os.Remove(us.filePath)
log.Printf("undo: cleared history")
}
+
+// LastError returns the error from the most recent failed Undo/Redo, or nil.
+// A nil change plus a nil LastError means the history/redo stack was empty.
+func (us *UndoStack) LastError() error {
+ us.mu.Lock()
+ defer us.mu.Unlock()
+ return us.lastErr
+}