lima-vm/lima · error

failed to create pipe for less: %w

Error message

failed to create pipe for less: %w

What it means

To display the change preview, limactl pipes `diff` output into the user's pager (usually `less`) via an os/exec StdinPipe. This error is returned when creating that pipe fails, which is rare and typically indicates process-resource exhaustion or an exec plumbing problem.

Source

Thrown at cmd/limactl/shell.go:649

				if !rsyncToTempDir {
					paths := []string{
						remoteSource,
						hostTmpDest,
					}

					if err := rsyncDirectory(ctx, cmd, rsync, paths); err != nil {
						return fmt.Errorf("failed to sync back the changes from guest instance to host temporary directory: %w", err)
					}
					rsyncToTempDir = true
				}
			}

			pagerArgs := pagerCommand()
			lessCmd := exec.CommandContext(ctx, pagerArgs[0], pagerArgs[1:]...)

			pipeIn, err := lessCmd.StdinPipe()
			if err != nil {
				return fmt.Errorf("failed to create pipe for less: %w", err)
			}
			if diffCmd != nil {
				diffCmd.Stdout = pipeIn
			}
			lessCmd.Stdout = cmd.OutOrStdout()
			lessCmd.Stderr = cmd.OutOrStderr()

			if err := lessCmd.Start(); err != nil {
				return fmt.Errorf("failed to start less: %w", err)
			}

			// Write rsync dry-run output first
			if stats != nil {
				rsyncHead := fmt.Sprintf("%s--- rsync dry-run statistics ---%s", colorGray, colorNone)
				diffHead := fmt.Sprintf("%s--- detailed diff --- %s", colorGray, colorNone)
				if diffCmd == nil {
					diffHead = fmt.Sprintf("%s--- detailed diff unavailable (`diff` not found) --- %s", colorGray, colorNone)
				}

View on GitHub (pinned to dd909d0973)

Solutions

  1. Check and raise the file descriptor limit: `ulimit -n` (raise via `ulimit -n 4096` or limits.conf).
  2. Close leaked FDs in the parent environment or restart the shell session to release resources.
  3. Skip the preview: choose "Yes" or "No" at the prompt instead of "View the changed contents".
  4. Retry the command after freeing system resources.
Defensive patterns

Strategy: validation

Validate before calling

ulimit -n | awk '{exit ($1 < 1024 ? 1 : 0)}' && echo 'fd limit OK' || echo 'raise ulimit -n before running limactl shell'

Try / catch

// pre-flight: raise soft fd limit if low
ulimit -n 4096 2>/dev/null || true
limactl shell default

Prevention

When it happens

Trigger: Choosing "View the changed contents" in the TTY prompt, when lessCmd.StdinPipe() returns an error: file-descriptor exhaustion (too many open FDs/ulimit -n reached), fork/exec resource limits, or the process is in a constrained sandbox.

Common situations: Shell sessions with very high open-FD counts (many sockets/files); containers with low RLIMIT_NOFILE; heavily constrained CI runners; PAGER pointed at a wrapper that closes fds unpredictably (less likely, since the pipe is created before exec).

Related errors


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