{"record":{"id":"78b90137920e089b","repo":"lima-vm/lima","slug":"expected-status-q-got-q-maybe-use-limactl-s","errorCode":null,"errorMessage":"expected status %#q, got %#q (maybe use `limactl stop -f`?)","messagePattern":"expected status %#q, got %#q \\(maybe use `limactl stop -f`\\?\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/instance/stop.go","lineNumber":32,"sourceCode":"\n\t\"github.com/sirupsen/logrus\"\n\n\t\"github.com/lima-vm/lima/v2/pkg/autostart\"\n\t\"github.com/lima-vm/lima/v2/pkg/driver/external/server\"\n\thostagentevents \"github.com/lima-vm/lima/v2/pkg/hostagent/events\"\n\t\"github.com/lima-vm/lima/v2/pkg/limatype\"\n\t\"github.com/lima-vm/lima/v2/pkg/limatype/filenames\"\n\t\"github.com/lima-vm/lima/v2/pkg/osutil\"\n\t\"github.com/lima-vm/lima/v2/pkg/store\"\n)\n\nfunc StopGracefully(ctx context.Context, inst *limatype.Instance, isRestart bool) error {\n\tif inst.Status != limatype.StatusRunning {\n\t\tif isRestart {\n\t\t\tlogrus.Warn(\"The instance is not running, continuing with the restart\")\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"expected status %#q, got %#q (maybe use `limactl stop -f`?)\", limatype.StatusRunning, inst.Status)\n\t}\n\n\tbegin := time.Now() // used for logrus propagation\n\tif requested, err := autostart.RequestStop(ctx, inst); err != nil && !errors.Is(err, autostart.ErrNotSupported) {\n\t\treturn fmt.Errorf(\"failed to request stop via autostart manager: %w\", err)\n\t} else if !requested {\n\t\tlogrus.Infof(\"Sending SIGINT to hostagent process %d\", inst.HostAgentPID)\n\t\tif err := osutil.SysKill(inst.HostAgentPID, osutil.SigInt); err != nil {\n\t\t\tlogrus.Error(err)\n\t\t}\n\t}\n\n\tlogrus.Info(\"Waiting for the host agent and the driver processes to shut down\")\n\terr := waitForHostAgentTermination(ctx, inst, begin)\n\tif err != nil {\n\t\treturn err\n\t}\n","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/instance/stop.go#L14-L50","documentation":"StopGracefully only stops instances whose status is StatusRunning. For a plain stop, a non-running instance is an error suggesting the instance may be in a broken/stale state and that a forced stop (`limactl stop -f`) is the remedy. For restarts it downgrades to a warning and continues.","triggerScenarios":"`limactl stop <name>` (via stopAction) or `limactl restart <name>` -> StopGracefully while inst.Status is anything other than Running (Stopped, Broken, Unknown, etc.).","commonSituations":"Stopping an already-stopped instance, an instance left in a broken state after a crashed VM process, stale instance metadata in ~/.lima after a host reboot.","solutions":["Use `limactl stop -f <instance>` to force-stop and clear the state","Check actual state with `limactl list` — if already stopped, no action needed","If status is stale/wrong, repair metadata or `limactl delete -f` and recreate","For restarts, the tool continues automatically; treat as warning only"],"exampleFix":"# before\nlimactl stop my-instance   # expected status \"Running\", got \"Broken\"\n# after\nlimactl stop -f my-instance\n","handlingStrategy":"validation","validationCode":"st, err := getInstanceStatus(instName) // e.g. limactl list --json -> .status\nif err != \"Running\" {\n    // skip graceful stop, or use forced stop\n    return stopForced(instName)\n}","typeGuard":"func isRunning(inst *limatype.Instance) bool {\n    return inst != nil && inst.Status == limatype.StatusRunning\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"maybe use `limactl stop -f`\") {\n    return stopForced(instName) // limactl stop -f\n}","preventionTips":["Check `limactl list` status before issuing stop","Use `stop -f` when status is Broken/Unknown","Handle the restart case where non-running is only a warning","Clean up stale instance dirs after host reboots"],"tags":["instance-state","stop","lifecycle"],"backgroundTag":"invalid-instance-state","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}