{"record":{"id":"cbff7ca7023890b9","repo":"GoogleContainerTools/skaffold","slug":"creating-parent-directory-w","errorCode":null,"errorMessage":"creating parent directory: %w","messagePattern":"creating parent directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/util/util.go","lineNumber":130,"sourceCode":"}\n\nfunc Ptr[T any](t T) *T {\n\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]","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/util/util.go#L112-L148","documentation":"VerifyOrCreateFile ensures the Skaffold config file exists, creating it (and its parents) if missing; this error wraps a failure of os.MkdirAll on the path's parent directory. MkdirAll fails when a component of the parent path exists as a non-directory, the process lacks write permission on an ancestor, or the filesystem is read-only. Called from ResolveConfigFile when bootstrapping the default skaffold config location.","triggerScenarios":"Running Skaffold when the config path (e.g. ~/.skaffold/config) does not exist and os.Stat reports IsNotExist, then os.MkdirAll on the parent fails — parent path component is a regular file, HOME is not writable, or the target filesystem is read-only.","commonSituations":"A stale file named `.skaffold` (instead of a directory) sits in $HOME; running in a container as a non-root user with a read-only or unwritable HOME; HOME pointing to a nonexistent/unwritable path in CI; disk full.","solutions":["Check that each component of the parent path is a directory: `ls -la $(dirname <path>)` — remove/rename any regular file with the same name.","Verify write permission on the ancestor directory (chmod/chown or run as the correct user).","Set HOME (or the config-path override) to a writable location.","Free disk space or remount the filesystem read-write if it is read-only."],"exampleFix":"# before: $HOME/.skaffold is a plain file, blocking MkdirAll\n$ ls -la ~ | grep .skaffold\n-rw-r--r-- 1 user user 0 .skaffold\n// after\n$ rm ~/.skaffold && mkdir -p ~/.skaffold","handlingStrategy":"validation","validationCode":"func canBootstrapConfig(path string) error {\n    dir := filepath.Dir(path)\n    for d := dir; d != \".\" && d != \"/\"; d = filepath.Dir(d) {\n        fi, err := os.Stat(d)\n        if err == nil && !fi.IsDir() {\n            return fmt.Errorf(\"%s exists and is not a directory\", d)\n        }\n    }\n    f, err := os.CreateTemp(dir, \".probe\")\n    if err != nil {\n        return fmt.Errorf(\"%s not writable: %w\", dir, err)\n    }\n    f.Close(); os.Remove(f.Name())\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := util.VerifyOrCreateFile(cfgPath); err != nil {\n    if strings.Contains(err.Error(), \"creating parent directory\") {\n        os.RemoveAll(filepath.Dir(cfgPath)) // remove stale non-directory component\n        return util.VerifyOrCreateFile(cfgPath)\n    }\n    return err\n}","preventionTips":["Never create plain files named like your config directories in $HOME.","Run Skaffold as a user with a writable HOME.","Point HOME (or the config path) at a writable volume in containers.","Check mounts are rw, not ro, before first-run config bootstrap."],"tags":["filesystem","mkdir","permissions","config"],"backgroundTag":"mkdir-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"}