lima-vm/lima · error
failed to run diff command: %w
Error message
failed to run diff command: %w
What it means
The preview runs `diff -ruN --color=always <hostCurrentDir> <hostTmpDest>` piped into the pager. `diff` exiting 1 just means files differ (expected, tolerated), but exit code >= 2 signals a real diff failure (unreadable files, missing directories, diff internal error). limactl surfaces that as this error, with the guest workdir preserved.
Source
Thrown at cmd/limactl/shell.go:688
rsyncHead,
stats.String(),
rawOutput,
diffHead,
)
if _, err := fmt.Fprint(pipeIn, combinedOutput); err != nil {
_ = pipeIn.Close()
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"}View on GitHub (pinned to dd909d0973)
Solutions
- Fix read permissions on the host directory contents (`chmod -R u+r`, or run as a user who can read them), then retry the preview.
- Confirm hostCurrentDir still exists and is accessible; recreate it if it was deleted, then choose "Yes" to sync back.
- Skip the preview and choose "Yes"/"No" at the prompt — sync-back does not require diff.
- Inspect the wrapped error output to identify the specific unreadable path reported by diff.
- Recover changes manually from destRsyncDir in the guest if the session cannot proceed.
Defensive patterns
Strategy: validation
Validate before calling
find . ! -readable -print -quit | grep -q . && echo 'unreadable files present: diff preview will fail (exit >= 2)' || echo 'all files readable, diff preview should work'
Try / catch
// prefer answering the prompt directly over debugging diff // diff exit 1 (files differ) is normal and NOT an error; only >= 2 aborts limactl shell default
Prevention
- Keep all files in synced workdirs readable by your user (avoid root-owned files from sudo-inside-guest).
- Don't delete host or temp directories while the preview prompt is open.
- Remember diff exit code 1 is expected when files differ — only >= 2 is a failure.
- Skip preview for workdirs with exotic file types (sockets, symlink loops).
When it happens
Trigger: Selecting "View the changed contents" when the diff process exits with code 2+: a file exists in one tree but is unreadable due to permissions, the host directory or temp staging dir disappeared mid-diff, symlink loops, or corrupted special files causing diff to abort.
Common situations: Host directory contains root-owned or 0600 files owned by another user; the host dir was deleted while the prompt was open; a concurrently-running process removes temp staging files mid-diff; very deep/odd file trees hitting diff limits.
Related errors
- failed to install plist to %s: %w
- failed to remove %s: %w
- failed to remove a directory %#q: %w
- failed to sync back the changes from guest instance to host
- failed to %s the autostart entry for instance %#q: %w
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/c3b43c69b06db5d2.
Report an issue: GitHub.