fix(rexctl): explain that migrate always backs up first

This commit is contained in:
Hampus committed 2026-11-29 05:55:01 +01:00
1 parent 6e88368195
commit 3aa9eb476e
3 files changed
+15 -5

No files matched your search

+9
View File
@@ -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
+4
View File
@@ -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:
+2 -5
View File
@@ -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")