abiosoft/colima · error
cannot read file '%s': %w
Error message
cannot read file '%s': %w
What it means
limaVM.Read is the environment's file-read primitive: it runs `sudo cat <fileName>` inside the guest over SSH and wraps any failure as 'cannot read file'. The wrapped error typically includes the non-zero exit of cat (file missing, permission issues even under sudo, I/O errors) or the underlying SSH/guest execution failure. Any Colima feature that reads a guest file (certs, runtime config detection) funnels through here.
Source
Thrown at environment/vm/lima/file.go:19
package lima
import (
"bytes"
"fmt"
"io/fs"
"os"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/abiosoft/colima/environment"
)
func (l limaVM) Read(fileName string) (string, error) {
s, err := l.RunOutput("sudo", "cat", fileName)
if err != nil {
return "", fmt.Errorf("cannot read file '%s': %w", fileName, err)
}
return s, err
}
func (l *limaVM) Write(fileName string, body []byte) error {
var stdin = bytes.NewReader(body)
dir := filepath.Dir(fileName)
if err := l.RunQuiet("sudo", "mkdir", "-p", dir); err != nil {
return fmt.Errorf("error creating directory '%s': %w", dir, err)
}
return l.RunWith(stdin, nil, "sudo", "sh", "-c", "cat > "+fileName)
}
func (l *limaVM) Stat(fileName string) (os.FileInfo, error) {
return newFileInfo(l, fileName)
}
var _ os.FileInfo = (*fileInfo)(nil)View on GitHub (pinned to c3a5f9184d)
Solutions
- Confirm the VM is actually running (`colima status`) before issuing reads.
- Check the exact guest path exists via `colima ssh -- sudo ls -la <path>` and create/fix it if missing.
- Retry after a full stop/start if the guest was in a transient state.
- In caller code, treat ENOENT-style wrapped errors for optional files as non-fatal rather than aborting.
Example fix
// before
body, err := vm.Read("/etc/containerd/config.toml")
if err != nil { return err } // aborts on missing optional file
// after
body, err := vm.Read("/etc/containerd/config.toml")
if err != nil {
if strings.Contains(err.Error(), "No such file") { body = "" } else { return err }
} Defensive patterns
Strategy: validation
Validate before calling
// guard reads: vm must be running, and optional files tolerated as absent
if !vm.Running(ctx) { return errors.New("vm not running") }
if _, err := vm.Stat(fileName); err != nil && isOptional(fileName) { return "", nil } Try / catch
Go: read, then on error inspect the chain; for optional configs treat ENOENT-like messages ("No such file") as empty result, propagate the rest. Prevention
- Check colima status before guest file reads
- Distinguish missing-file from ssh failures in handlers
- Retry after full stop/start when the guest is mid-boot
When it happens
Trigger: Reading a guest path that does not exist (e.g. a config file not yet created by the runtime); calling Read while the VM is stopping/stopped so the SSH command fails; guest disk I/O errors.
Common situations: Automation scripts probing optional files in the guest; races where a file is read before the guest service creates it; profile in a broken half-started state.
Related errors
- error creating directory '%s': %w
- error reading ssh config: %w
- error modifying %s: %w
- failed to create dnsmasq config directory: %w
- failed to write dnsmasq config: %w
AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15).
Data as JSON: /api/errors/177e3521823e65da.
Report an issue: GitHub.