{"record":{"id":"8ababe94c5c83192","repo":"GoogleContainerTools/skaffold","slug":"creating-file-w","errorCode":null,"errorMessage":"creating file: %w","messagePattern":"creating file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/util/util.go","lineNumber":133,"sourceCode":"\to := t\n\treturn &o\n}\n\nfunc IsURL(s string) bool {\n\treturn strings.HasPrefix(s, \"http://\") || strings.HasPrefix(s, \"https://\")\n}\n\n// VerifyOrCreateFile checks if a file exists at the given path,\n// and if not, creates all parent directories and creates the file.\nfunc VerifyOrCreateFile(path string) error {\n\t_, err := os.Stat(path)\n\tif err != nil && os.IsNotExist(err) {\n\t\tdir := filepath.Dir(path)\n\t\tif err = os.MkdirAll(dir, 0744); err != nil {\n\t\t\treturn fmt.Errorf(\"creating parent directory: %w\", err)\n\t\t}\n\t\tif _, err = os.Create(path); err != nil {\n\t\t\treturn fmt.Errorf(\"creating file: %w\", err)\n\t\t}\n\t\treturn nil\n\t}\n\treturn err\n}\n\n// Expand replaces placeholders for a given key with a given value.\n// It supports the ${key} and the $key syntax.\nfunc Expand(text, key, value string) string {\n\ttext = strings.ReplaceAll(text, \"${\"+key+\"}\", value)\n\n\tindices := regexp.MustCompile(`\\$`+key).FindAllStringIndex(text, -1)\n\n\tfor i := len(indices) - 1; i >= 0; i-- {\n\t\tfrom := indices[i][0]\n\t\tto := indices[i][1]\n\n\t\tif to >= len(text) || !isAlphaNum(text[to]) {","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/util/util.go#L115-L151","documentation":"VerifyOrCreateFile creates the config file with os.Create after ensuring parent directories exist; this error wraps a failure of that os.Create call. It fires when the parent directory exists but is not writable by the current user, or a rare race removes the directory between MkdirAll and Create. Called from ResolveConfigFile on first-run config bootstrap.","triggerScenarios":"os.Stat reports the config path missing, parent directories were created (or already existed), but os.Create(path) fails — typically EACCES on the parent directory, or the path exists as a dangling entry/special file that cannot be opened for writing.","commonSituations":"Running as a non-root user in a container whose HOME is owned by root; a read-only bind mount for the config directory; SELinux/AppArmor denying writes to the config location; disk quota exceeded.","solutions":["Ensure the parent directory is writable: chmod u+w $(dirname <path>) or chown it to the running user.","Point Skaffold at a writable config path (fix HOME or the config override flag/env).","Remove any non-regular file occupying the path (ls -la <path>; special file/device node).","Check disk quota/space and mount flags (rw vs ro) on the volume holding the config."],"exampleFix":"# before: config dir owned by root\n$ ls -ld ~/.skaffold\ndrwxr-xr-x 2 root root ~/.skaffold\n// after\n$ sudo chown -R $(id -u):$(id -g) ~/.skaffold","handlingStrategy":"validation","validationCode":"func ensureWritableDir(dir string) error {\n    if err := os.MkdirAll(dir, 0o744); err != nil {\n        return err\n    }\n    probe, err := os.CreateTemp(dir, \".writable\")\n    if err != nil {\n        return fmt.Errorf(\"%s not writable: %w\", dir, err)\n    }\n    probe.Close(); os.Remove(probe.Name())\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := util.VerifyOrCreateFile(cfgPath); err != nil {\n    if strings.Contains(err.Error(), \"creating file\") && errors.Is(err, fs.ErrPermission) {\n        return fmt.Errorf(\"fix ownership of %s: %w\", filepath.Dir(cfgPath), err)\n    }\n    return err\n}","preventionTips":["chown config directories to the user running Skaffold (common in containers with root-owned HOME).","Verify the target filesystem is mounted read-write and quota is not exhausted.","In CI, set HOME to an ephemeral writable path (e.g. $RUNNER_TEMP).","Check SELinux/AppArmor denials if permissions look correct but creation fails."],"tags":["filesystem","file-create","permissions","config"],"backgroundTag":"file-create-permission-denied","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}