{"record":{"id":"62b8028e2c25a2a9","repo":"lima-vm/lima","slug":"failed-to-run-v-w-output-s","errorCode":null,"errorMessage":"failed to run %v: %w (output=%s)","messagePattern":"failed to run (.+?): %w \\(output=(.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/driver/vz/vz_driver_darwin.go","lineNumber":497,"sourceCode":"func (l *LimaVzDriver) RunGUI(_ context.Context) error {\n\tif l.canRunGUI() {\n\t\ttitle := fmt.Sprintf(\"Lima: %s\", l.Instance.Name)\n\t\treturn l.machine.StartGraphicApplication(1920, 1200, vz.WithWindowTitle(title))\n\t}\n\treturn fmt.Errorf(\"RunGUI is not supported for the given driver '%s' and display '%s'\", \"vz\", *l.Instance.Config.Video.Display)\n}\n\nfunc (l *LimaVzDriver) requestStopViaSSH(ctx context.Context) error {\n\tsshExe, err := sshutil.NewSSHExe()\n\tif err != nil {\n\t\treturn err\n\t}\n\tcmd := exec.CommandContext(ctx, sshExe.Exe,\n\t\tappend(sshExe.Args, \"-F\", l.Instance.SSHConfigFile, l.Instance.Hostname, \"--\",\n\t\t\t\"sudo\", \"/sbin/shutdown\", \"-h\", \"now\")...)\n\tlogrus.Infof(\"Running shutdown command in the VM: %v\", cmd.Args)\n\tif out, err := cmd.CombinedOutput(); err != nil {\n\t\treturn fmt.Errorf(\"failed to run %v: %w (output=%s)\", cmd.Args, err, string(out))\n\t}\n\treturn nil\n}\n\nfunc (l *LimaVzDriver) Stop(ctx context.Context) error {\n\tlogrus.Info(\"Shutting down VZ\")\n\tcanStop := l.machine.CanRequestStop()\n\n\tif canStop {\n\t\t_, err := l.machine.RequestStop()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif *l.Instance.Config.OS == limatype.DARWIN {\n\t\t\t// macOS VM does not respond to l.machine.RequestStop(),\n\t\t\t// so we need to run `shutdown -h now` in the VM via SSH for graceful shutdown.\n\t\t\tif err := l.requestStopViaSSH(ctx); err != nil {","sourceCodeStart":479,"sourceCodeEnd":515,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/driver/vz/vz_driver_darwin.go#L479-L515","documentation":"Lima's VZ driver stops the VM by SSHing into the guest and running `sudo /sbin/shutdown -h now`. If the ssh command exits non-zero, the driver wraps the exit error plus the combined stdout/stderr output in this error. It means the guest-side shutdown command did not run successfully.","triggerScenarios":"requestStopViaSSH is called (from Stop) and the `ssh ... -- sudo /sbin/shutdown -h now` command returns a non-zero exit code, e.g. ssh cannot authenticate, the guest is already half-down, or shutdown is not present/allowed via sudo.","commonSituations":"Guest agent/sshd already died during shutdown race; SSH key or host key mismatch; guest booted without sudo rights for the lima user; a slow/busy guest where init rejected the shutdown request; wiping or replacing files under ~/.lima that hold the SSH config.","solutions":["Re-run `limactl stop <instance>`; transient races during shutdown often succeed on retry","Check ssh connectivity manually: `limactl shell <instance> -- true` or `ssh -F ~/.lima/<instance>/ssh.config lima-<instance>` to see the underlying failure","Inspect the captured output in the error message (output=...) for the guest-side reason (e.g. sudo: no tty, command not found)","If the guest is stuck, use `limactl stop --force <instance>` to kill the VM without the graceful ssh shutdown","Regenerate the instance ssh config (`limactl factory-reset`) if keys/config under ${LIMA_HOME} were modified"],"exampleFix":"// before (debugging raw failure)\nerr := driver.Stop(ctx) // opaque\n// after (get details)\nif err := driver.Stop(ctx); err != nil {\n    log.Printf(\"stop failed: %v; try: limactl shell <inst> -- sudo /sbin/shutdown -h now\", err)\n}","handlingStrategy":"try-catch","validationCode":"// before stopping, verify guest is reachable\nout, err := exec.Command(\"limactl\", \"shell\", inst, \"--\", \"true\").CombinedOutput()\nif err != nil {\n    // ssh already broken: use force stop instead of graceful\n    exec.Command(\"limactl\", \"stop\", \"--force\", inst).Run()\n}","typeGuard":"// Go: unwrap and inspect\nvar ee *exec.ExitError\nif errors.As(err, &ee) { /* ssh exit code in ee.ExitCode() */ }","tryCatchPattern":"if err := driver.Stop(ctx); err != nil {\n    if strings.Contains(err.Error(), \"failed to run\") {\n        _ = driver.Stop(ctx) // retry once, then force\n    }\n}","preventionTips":["Don't edit ssh.config or keys under ${LIMA_HOME} manually","Check `limactl list` state before stopping","Prefer `limactl stop` over killing VM processes","Keep guest systemd healthy so shutdown doesn't race sshd"],"tags":["ssh","shutdown","vz-driver","macos"],"backgroundTag":"ssh-command-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}