{"record":{"id":"8a012b6c8f80be66","repo":"golang/go","slug":"failed-to-create-cache-directory-w","errorCode":null,"errorMessage":"failed to create cache directory: %w","messagePattern":"failed to create cache directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modfetch/cache.go","lineNumber":178,"sourceCode":"\t}\n\tif err := os.MkdirAll(filepath.Dir(path), 0o777); err != nil {\n\t\treturn nil, err\n\t}\n\treturn lockedfile.MutexAt(path).Lock()\n}\n\n// SideLock locks a file within the module cache that previously guarded\n// edits to files outside the cache, such as go.sum and go.mod files in the\n// user's working directory.\n// If err is nil, the caller MUST eventually call the unlock function.\nfunc SideLock(ctx context.Context) (unlock func(), err error) {\n\tif err := checkCacheDir(ctx); err != nil {\n\t\treturn nil, err\n\t}\n\n\tpath := filepath.Join(cfg.GOMODCACHE, \"cache\", \"lock\")\n\tif err := os.MkdirAll(filepath.Dir(path), 0o777); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create cache directory: %w\", err)\n\t}\n\n\treturn lockedfile.MutexAt(path).Lock()\n}\n\n// A cachingRepo is a cache around an underlying Repo,\n// avoiding redundant calls to ModulePath, Versions, Stat, Latest, and GoMod (but not CheckReuse or Zip).\n// It is also safe for simultaneous use by multiple goroutines\n// (so that it can be returned from Lookup multiple times).\n// It serializes calls to the underlying Repo.\ntype cachingRepo struct {\n\tpath          string\n\tversionsCache par.ErrCache[string, *Versions]\n\tstatCache     par.ErrCache[string, *RevInfo]\n\tlatestCache   par.ErrCache[struct{}, *RevInfo]\n\tgomodCache    par.ErrCache[string, []byte]\n\n\tonce     sync.Once","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modfetch/cache.go#L160-L196","documentation":"Thrown by `modfetch.SideLock` when `os.MkdirAll` fails to create the `cache/lock` parent directory inside GOMODCACHE. SideLock acquires a mutex on a file in the module cache to serialize edits to files outside the cache (go.sum, go.mod). If the cache directory structure cannot be created — due to permissions, disk full, or path issues — this wraps the underlying OS error with %w.","triggerScenarios":"Calling SideLock when GOMODCACHE/cache/ cannot be created. MkdirAll fails due to: permission denied on a parent directory, read-only filesystem, disk full, invalid path characters, or GOMODCACHE pointing to a location that can't be created.","commonSituations":"GOMODCACHE set to a read-only directory; insufficient permissions on the cache root; disk full; GOMODCACHE on a network mount with write failures; containerized environments with volume permission issues.","solutions":["Check and fix permissions on GOMODCACHE: `chmod -R u+w $(go env GOMODCACHE)`","Ensure GOMODCACHE points to a writable directory","Free disk space if full","Verify the path is valid and accessible: `ls -la $(go env GOMODCACHE)/cache/`"],"exampleFix":"# before: GOMODCACHE points to read-only location\nexport GOMODCACHE=/usr/local/go/pkg/mod\n# after: point to writable location\nexport GOMODCACHE=$HOME/go/pkg/mod","handlingStrategy":"validation","validationCode":"// Verify cache directory is writable before operations\nimport \"os\"\n\nfunc ensureCacheWritable() error {\n    cacheDir := os.Getenv(\"GOMODCACHE\")\n    if cacheDir == \"\" {\n        cacheDir = filepath.Join(os.Getenv(\"GOPATH\"), \"pkg\", \"mod\")\n    }\n    testFile := filepath.Join(cacheDir, \"cache\", \".writetest\")\n    return os.WriteFile(testFile, []byte(\"ok\"), 0644)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure GOMODCACHE is on a writable filesystem with adequate permissions","Check disk space before running module-heavy operations","In containers, mount GOMODCACHE on a writable volume"],"tags":["go","go-mod","cache","filesystem","permissions","locking"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}