{"record":{"id":"6ecbea7becf71c27","repo":"lima-vm/lima","slug":"failed-to-create-parent-directory-for-path-q-w","errorCode":null,"errorMessage":"failed to create parent directory for path %#q: %w","messagePattern":"failed to create parent directory for path %#q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/guestagent/fakecloudinit/fakecloudinit_darwin.go","lineNumber":352,"sourceCode":"\t\treturn fmt.Errorf(\"failed to write to sudoers file %#q for user %#q: %w\", sudoersPath, userName, err)\n\t}\n\treturn f.Close()\n}\n\nfunc writeFiles(ctx context.Context, entry cloudinittypes.WriteFile) error {\n\tif entry.Path == \"\" {\n\t\treturn errors.New(\"path is required for write_files entry\")\n\t}\n\tperm := os.FileMode(0o644)\n\tif entry.Permissions != \"\" {\n\t\tp, err := strconv.ParseUint(entry.Permissions, 8, 32)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"invalid permissions %#q for path %#q: %w\", entry.Permissions, entry.Path, err)\n\t\t}\n\t\tperm = os.FileMode(p)\n\t}\n\tif err := os.MkdirAll(filepath.Dir(entry.Path), 0o755); err != nil {\n\t\treturn fmt.Errorf(\"failed to create parent directory for path %#q: %w\", entry.Path, err)\n\t}\n\tif err := os.WriteFile(entry.Path, []byte(entry.Content), perm); err != nil {\n\t\treturn fmt.Errorf(\"failed to write file for path %#q: %w\", entry.Path, err)\n\t}\n\tif entry.Owner != \"\" {\n\t\tcmd := exec.CommandContext(ctx, \"chown\", entry.Owner, entry.Path)\n\t\tlogrus.Infof(\"Executing command: %v\", cmd.Args)\n\t\tif output, err := cmd.CombinedOutput(); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to execute command %v: %w (output=%#q)\", cmd.Args, err, output)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc setResolvConf(ctx context.Context, resolvConf *cloudinittypes.ResolvConf) error {\n\t// FIXME: avoid hardcoding the primary network name\n\tconst primaryNetwork = \"Ethernet\"\n\tcmd := exec.CommandContext(ctx, \"networksetup\", append([]string{\"-setdnsservers\", primaryNetwork}, resolvConf.Nameservers...)...)","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/guestagent/fakecloudinit/fakecloudinit_darwin.go#L334-L370","documentation":"Before writing a write_files entry, the fake cloud-init code runs `os.MkdirAll` on the entry's parent directory with mode 0755. When that fails, this error wraps the OS error. It usually means a path component exists as a regular file, or the process lacks permission to create the directory.","triggerScenarios":"A write_files entry whose `path` has a parent directory that cannot be created: the parent exists as a file (e.g. path /etc/foo where /etc/foo is a file), the volume is read-only, or the guestagent user lacks write permission at that location.","commonSituations":"User-data writes to a path that collides with an existing file; writing under read-only mounts or system dirs owned by root while running unprivileged; typo in the target path creating an unintended deep hierarchy.","solutions":["Verify the `path` in the write_files entry and correct any typo that points at a file used as a directory.","Ensure the parent path exists as a directory, or that no component of it is a regular file.","Run the guestagent with sufficient privileges, or write to a user-writable location.","Check the wrapped os.MkdirAll error text for the exact failing component (e.g. 'not a directory', 'permission denied')."],"exampleFix":"// before\npath: /etc/hosts/custom.conf  # /etc/hosts is a file\n// after\npath: /etc/hosts.d/custom.conf","handlingStrategy":"validation","validationCode":"for _, e := range userData.WriteFiles {\n    dir := filepath.Dir(e.Path)\n    if fi, err := os.Stat(dir); err == nil && !fi.IsDir() {\n        return fmt.Errorf(\"path %q: parent %q is a file\", e.Path, dir)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := processUserData(ctx, data); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && (errors.Is(pe.Err, syscall.ENOTDIR) || errors.Is(pe.Err, syscall.EACCES)) {\n        log.Printf(\"fix path/permissions: %v\", err)\n    }\n}","preventionTips":["Verify each write_files path's parent is a directory, not an existing file.","Avoid writing into root-owned system paths unless running privileged.","Keep target paths under a dedicated provisioning directory."],"tags":["cloud-init","macos","filesystem","permissions"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}