abiosoft/colima · error

cannot stat file '%s': %w

Error message

cannot stat file '%s': %w

What it means

statError is the single wrapping helper for guest-side file stat failures in limaVM.Stat/newFileInfo: the stat is performed by running a stats command in the guest and parsing its output; any execution or parse-level failure is returned as "cannot stat file '<name>'". It is the limaVM equivalent of os.Stat's error, carrying the guest command error as the cause.

Source

Thrown at environment/vm/lima/file.go:74

		return info, statError(filename, err)
	}
	info.name = filename
	info.size, _ = strconv.ParseInt(stats[0], 10, 64)
	info.mode = func() fs.FileMode {
		mode, _ := strconv.ParseUint(stats[1], 10, 32)
		return fs.FileMode(mode)
	}()
	info.modTime = func() time.Time {
		unix, _ := strconv.ParseInt(stats[2], 10, 64)
		return time.Unix(unix, 0)
	}()
	info.isDir = stats[3] == "directory"

	return info, nil
}

func statError(filename string, err error) error {
	return fmt.Errorf("cannot stat file '%s': %w", filename, err)
}

// IsDir implements fs.FileInfo
func (f fileInfo) IsDir() bool { return f.isDir }

// ModTime implements fs.FileInfo
func (f fileInfo) ModTime() time.Time { return f.modTime }

// Mode implements fs.FileInfo
func (f fileInfo) Mode() fs.FileMode { return f.mode }

// Name implements fs.FileInfo
func (f fileInfo) Name() string { return f.name }

// Size implements fs.FileInfo
func (f fileInfo) Size() int64 { return f.size }

// Sys implements fs.FileInfo

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Use it as an existence check: a non-nil error means absent-or-unreachable; distinguish by first checking vm.Running(ctx).
  2. Confirm the path with `colima ssh -- stat <path>`.
  3. Retry after the guest has fully started when racing boot.
  4. For custom images, ensure standard GNU coreutils behavior for stat-like output.

Example fix

// before
if _, err := vm.Stat("/run/containerd/containerd.sock"); err != nil { return err }

// after
if _, err := vm.Stat("/run/containerd/containerd.sock"); err != nil {
    if !vm.Running(ctx) { return fmt.Errorf("vm not running: %w", err) }
    // treat as not-yet-created: wait or skip
}
Defensive patterns

Strategy: validation

Validate before calling

// existence check pattern around Stat
if !vm.Running(ctx) { return errors.New("vm not running; cannot stat") }
_, err := vm.Stat(fileName)
exists := err == nil

Try / catch

Go: treat any stat error as not-exists only when vm.Running(ctx) is true; otherwise surface the state problem.

Prevention

When it happens

Trigger: Calling Stat for a path that does not exist in the guest; guest not running / SSH failing so the stats command errors; parse failures when the guest output shape is unexpected (nonstandard coreutils in custom images).

Common situations: Runtime integrations probing for the existence of sockets/config files in the guest before acting; startup flows that check containerd/docker state files.

Related errors


AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15). Data as JSON: /api/errors/afc6b0f26ec4e801. Report an issue: GitHub.