From 3aa9eb476e51cf656d1e0bf77634bdfeb4485ccf Mon Sep 17 00:00:00 2001 From: Hampus Date: Sun, 29 Nov 2026 05:38:08 +0100 Subject: [PATCH] fix(rexctl): explain that migrate always backs up first --- fluxer_rexctl/cmd/flagerror.go | 9 +++++++++ fluxer_rexctl/cmd/migrate.go | 4 ++++ fluxer_rexctl/cmd/root.go | 7 ++----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/fluxer_rexctl/cmd/flagerror.go b/fluxer_rexctl/cmd/flagerror.go index 57be08461..d3b7d71e6 100644 --- a/fluxer_rexctl/cmd/flagerror.go +++ b/fluxer_rexctl/cmd/flagerror.go @@ -7,9 +7,18 @@ import ( "fmt" "strings" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) +func flagError(c *cobra.Command, err error) (msg, fix string) { + var unknown *pflag.NotExistError + if c.Name() == "migrate" && errors.As(err, &unknown) && unknown.GetSpecifiedName() == "no-backup" { + return "rexctl migrate has no --no-backup.", "rexctl migrate always backs up first, because it needs that backup to go back if the change fails and for rexctl migrate --undo. Run rexctl migrate again without --no-backup." + } + return flagErrorText(err), "Run " + c.CommandPath() + " --help to see every flag." +} + func flagErrorText(err error) string { var missing *pflag.ValueRequiredError var invalid *pflag.InvalidValueError diff --git a/fluxer_rexctl/cmd/migrate.go b/fluxer_rexctl/cmd/migrate.go index 9366e1e4b..a60ac94c7 100644 --- a/fluxer_rexctl/cmd/migrate.go +++ b/fluxer_rexctl/cmd/migrate.go @@ -127,6 +127,8 @@ func newMigrateCmd(app *App) *cobra.Command { return c } +const migrateBackupFix = "rexctl migrate always backs up first and has no --no-backup, because it needs that backup to go back if the change fails and for rexctl migrate --undo. Run rexctl backup to try the backup on its own, fix what it reports, then run rexctl migrate again." + const undoUsage = "--undo takes move, kv, storage, s3 or files. To leave the native runtime or one Rust process, restore the backup from before the change with rexctl restore." var undoTargets = []string{undoMove, string(migrate.OptKV), string(migrate.OptStorage), migrate.ToS3, migrate.ToFiles} @@ -432,6 +434,8 @@ func executeMigrate(ctx context.Context, app *App, inst *instance.Instance, step return r, migrate.State{}, refused case errors.As(err, &fail) && fail.Phase == migrate.PhasePreflight: return r, migrate.State{}, &ui.ExitError{Code: ui.ExitRefused, Msg: "rexctl didn't change anything.", Fix: migrateReason(fail.Err), Err: err} + case errors.As(err, &fail) && fail.Phase == migrate.PhaseBackup && ctx.Err() == nil: + return r, migrate.State{}, ui.Wrap(err, "The backup before the change failed, so rexctl didn't change anything. "+migrateReason(fail.Err), migrateBackupFix) case errors.As(err, &fail): return r, migrate.State{}, ui.Wrap(err, "rexctl didn't change anything.", migrateReason(fail.Err)) case err != nil: diff --git a/fluxer_rexctl/cmd/root.go b/fluxer_rexctl/cmd/root.go index 83c14c627..28a1a1c22 100644 --- a/fluxer_rexctl/cmd/root.go +++ b/fluxer_rexctl/cmd/root.go @@ -144,11 +144,8 @@ func newRoot(app *App) *cobra.Command { _ = display.apply(app.UI) app.init(c) app.UI.Begin(c.CommandPath()) - return &ui.ExitError{ - Code: ui.ExitUsage, - Msg: flagErrorText(err), - Fix: "Run " + c.CommandPath() + " --help to see every flag.", - } + msg, fix := flagError(c, err) + return &ui.ExitError{Code: ui.ExitUsage, Msg: msg, Fix: fix} }) pf := root.PersistentFlags() pf.BoolP("help", "h", false, "show help for a command")