abiosoft/colima · error

error preparing cache dir: %w

Error message

error preparing cache dir: %w

What it means

Raised by downloadFile before any network I/O: os.MkdirAll on the cache directory (config.CacheDir()/caches, entries named by sha256 of the URL) failed. The %w wraps the underlying *fs.PathError, so the real errno (EACCES, ENOTDIR, EROFS, ENOSPC) is visible one level down.

Source

Thrown at util/downloader/download.go:123

func CacheFilename(url string) string {
	return filepath.Join(config.CacheDir(), "caches", shautil.SHA256(url).String())
}

func (d downloader) cacheDownloadingFileName(url string) string {
	return CacheFilename(url) + ".downloading"
}

func (d downloader) resumeInfoPath(url string) string {
	return CacheFilename(url) + ".resume"
}

func (d downloader) downloadFile(r Request) (err error) {
	cacheDownloadingFilename := d.cacheDownloadingFileName(r.URL)

	// create cache directory
	cacheDir := filepath.Dir(cacheDownloadingFilename)
	if err := os.MkdirAll(cacheDir, 0755); err != nil {
		return fmt.Errorf("error preparing cache dir: %w", err)
	}

	if err := fileDownloader.Download(r, cacheDownloadingFilename); err != nil {
		return err
	}

	// validate download if SHA is present
	if r.SHA != nil {
		if err := r.SHA.validateDownload(r.URL, cacheDownloadingFilename); err != nil {
			// move file to allow subsequent re-download
			_ = os.Rename(cacheDownloadingFilename, cacheDownloadingFilename+".invalid")
			return fmt.Errorf("error validating SHA sum for '%s': %w", path.Base(r.URL), err)
		}
	}

	// move completed download to final location
	if err := os.Rename(cacheDownloadingFilename, CacheFilename(r.URL)); err != nil {
		return fmt.Errorf("error finalizing download: %w", err)

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Take the path from the wrapped *fs.PathError, run ls -ld on it, and chown/chmod so the current user can write
  2. Remove root-owned cache leftovers (sudo rm -rf on the caches dir) or relocate the cache
  3. Ensure no parent path component is a plain file (ENOTDIR in the wrapped error)
  4. Free disk space or remount the volume read-write
Defensive patterns

Strategy: validation

Validate before calling

cacheDir := filepath.Dir(downloader.CacheFilename(req.URL))
if err := os.MkdirAll(cacheDir, 0o755); err != nil {
    return err
}
f, err := os.CreateTemp(cacheDir, ".writecheck-*")
if err != nil {
    return fmt.Errorf("cache dir not writable: %w", err)
}
_ = f.Close()
_ = os.Remove(f.Name())
// safe to call downloader.Download now

Try / catch

cacheFile, err := downloader.Download(host, req)
if err != nil {
    var pathErr *fs.PathError
    if errors.As(err, &pathErr) {
        log.Printf("cache path %s failed: %v", pathErr.Path, pathErr.Err) // EACCES/EROFS/ENOSPC/ENOTDIR
    }
    return err
}

Prevention

When it happens

Trigger: Calling downloader.Download or DownloadToGuest when the caches dir or a parent is not writable (EACCES), a parent path component is a regular file (ENOTDIR), the volume is read-only (EROFS), or the disk is full (ENOSPC). Note MkdirAll is a no-op when the dir already exists, so an unwritable existing dir passes this check and fails later instead.

Common situations: Cache dir created by an earlier sudo/root run so the current user cannot write; HOME or the cache env var pointing at an unwritable location; colima running in a container or against a read-only mount; cache-cleaner tools racing the run.

Related errors


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