{"record":{"id":"419350cbf6a270d2","repo":"abiosoft/colima","slug":"error-preparing-cache-dir-w","errorCode":null,"errorMessage":"error preparing cache dir: %w","messagePattern":"error preparing cache dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/downloader/download.go","lineNumber":123,"sourceCode":"func CacheFilename(url string) string {\n\treturn filepath.Join(config.CacheDir(), \"caches\", shautil.SHA256(url).String())\n}\n\nfunc (d downloader) cacheDownloadingFileName(url string) string {\n\treturn CacheFilename(url) + \".downloading\"\n}\n\nfunc (d downloader) resumeInfoPath(url string) string {\n\treturn CacheFilename(url) + \".resume\"\n}\n\nfunc (d downloader) downloadFile(r Request) (err error) {\n\tcacheDownloadingFilename := d.cacheDownloadingFileName(r.URL)\n\n\t// create cache directory\n\tcacheDir := filepath.Dir(cacheDownloadingFilename)\n\tif err := os.MkdirAll(cacheDir, 0755); err != nil {\n\t\treturn fmt.Errorf(\"error preparing cache dir: %w\", err)\n\t}\n\n\tif err := fileDownloader.Download(r, cacheDownloadingFilename); err != nil {\n\t\treturn err\n\t}\n\n\t// validate download if SHA is present\n\tif r.SHA != nil {\n\t\tif err := r.SHA.validateDownload(r.URL, cacheDownloadingFilename); err != nil {\n\t\t\t// move file to allow subsequent re-download\n\t\t\t_ = os.Rename(cacheDownloadingFilename, cacheDownloadingFilename+\".invalid\")\n\t\t\treturn fmt.Errorf(\"error validating SHA sum for '%s': %w\", path.Base(r.URL), err)\n\t\t}\n\t}\n\n\t// move completed download to final location\n\tif err := os.Rename(cacheDownloadingFilename, CacheFilename(r.URL)); err != nil {\n\t\treturn fmt.Errorf(\"error finalizing download: %w\", err)","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/util/downloader/download.go#L105-L141","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Take the path from the wrapped *fs.PathError, run ls -ld on it, and chown/chmod so the current user can write","Remove root-owned cache leftovers (sudo rm -rf on the caches dir) or relocate the cache","Ensure no parent path component is a plain file (ENOTDIR in the wrapped error)","Free disk space or remount the volume read-write"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"cacheDir := filepath.Dir(downloader.CacheFilename(req.URL))\nif err := os.MkdirAll(cacheDir, 0o755); err != nil {\n    return err\n}\nf, err := os.CreateTemp(cacheDir, \".writecheck-*\")\nif err != nil {\n    return fmt.Errorf(\"cache dir not writable: %w\", err)\n}\n_ = f.Close()\n_ = os.Remove(f.Name())\n// safe to call downloader.Download now","typeGuard":null,"tryCatchPattern":"cacheFile, err := downloader.Download(host, req)\nif err != nil {\n    var pathErr *fs.PathError\n    if errors.As(err, &pathErr) {\n        log.Printf(\"cache path %s failed: %v\", pathErr.Path, pathErr.Err) // EACCES/EROFS/ENOSPC/ENOTDIR\n    }\n    return err\n}","preventionTips":["Never run colima partly under sudo and partly as a user — mixed ownership of the cache dir is the top cause","Pre-flight check writability of the cache dir before starting large downloads","Keep the cache dir on local, writable storage and exclude it from cleanup tools"],"tags":["filesystem","cache","permissions","download"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}