lima-vm/lima · error

failed to wait for less command: %w

Error message

failed to wait for less command: %w

What it means

limactl's shell/preview flow pipes diff output through a `less` pager (returned by pagerCommand) and returns this error when lessCmd.Wait() reports a non-zero exit. It means the pager process itself failed or was terminated abnormally, not that the rsync diff content was bad. It is thrown in askUserForRsyncBack, which shows the user a colored diff of files to sync and asks whether to proceed.

Source

Thrown at cmd/limactl/shell.go:696

					return fmt.Errorf("failed to write rsync stats to pager: %w", err)
				}
			}

			if diffCmd != nil {
				if err := diffCmd.Run(); err != nil {
					// Command `diff` returns exit code 1 when files differ.
					var exitErr *exec.ExitError
					if errors.As(err, &exitErr) && exitErr.ExitCode() >= 2 {
						_ = pipeIn.Close()
						return fmt.Errorf("failed to run diff command: %w", err)
					}
				}
			}

			_ = pipeIn.Close()

			if err := lessCmd.Wait(); err != nil {
				return fmt.Errorf("failed to wait for less command: %w", err)
			}
		}
	}
}

// pagerCommand returns the pager command and arguments to use for viewing colored diff output.
func pagerCommand() []string {
	pager := strings.TrimSpace(os.Getenv("PAGER"))
	if pager == "" {
		return []string{"less", "-R"}
	}
	args := strings.Fields(pager)
	if filepath.Base(args[0]) != "less" {
		return args
	}
	if lessHasRawColorFlag(args[1:]) {
		return args
	}

View on GitHub (pinned to dd909d0973)

Solutions

  1. Check $PAGER and $LESS environment variables for invalid settings and unset or fix them
  2. Re-run the command with the pager disabled (e.g. PAGER=cat or GIT_PAGER=cat equivalent) to bypass `less`
  3. Verify `less` is installed and works: run `echo test | less` and confirm normal exit
  4. Ensure the terminal is a real TTY with a valid TERM setting; avoid invoking interactive limactl shell from non-interactive CI jobs

Example fix

// before: PAGER=/usr/bin/less -FX with broken -X in old less
// after
export PAGER=less   # or unset PAGER to use the default
Defensive patterns

Strategy: fallback

Validate before calling

if ! command -v less >/dev/null 2>&1; then echo 'less missing; set PAGER=cat' >&2; fi
echo probe | less -F >/dev/null 2>&1 || export PAGER=cat

Try / catch

if ! limactl shell default true; then
  export PAGER=cat
  limactl shell default <cmd> || exit $?
fi

Prevention

When it happens

Trigger: Running `limactl shell <inst> <cmd>` (shellAction) into a path where askUserForRsyncBack displays a diff in the `less` pager and the pager exits non-zero: user presses q mid-session in some less versions configured to exit with error, terminal closed while pager active, or the resolved $PAGER/less binary is broken or missing required terminal support.

Common situations: PAGER set to a non-pager command or a wrapper script that fails; running inside environments with no/wrong TERM (cron, CI, minimal containers) where less can't initialize; user quitting less with an error exit code; broken LESSOPEN filter scripts.

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/7bb5c6377214dd13. Report an issue: GitHub.