{"record":{"id":"c771c29653cc783b","repo":"lima-vm/lima","slug":"failed-to-write-file-for-path-q-w","errorCode":null,"errorMessage":"failed to write file for path %#q: %w","messagePattern":"failed to write file for path %#q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/guestagent/fakecloudinit/fakecloudinit_darwin.go","lineNumber":126,"sourceCode":"\t}\n\tfor _, m := range userData.Mounts {\n\t\tif err = mountFSTabEntry(m); err != nil {\n\t\t\terrs = append(errs, fmt.Errorf(\"failed to mount fstab entry %v: %w\", m, err))\n\t\t}\n\t}\n\tif userData.Timezone != \"\" {\n\t\tif err = setTimezone(ctx, userData.Timezone); err != nil {\n\t\t\terrs = append(errs, fmt.Errorf(\"failed to set timezone: %w\", err))\n\t\t}\n\t}\n\tfor _, u := range userData.Users {\n\t\tif err := createUser(ctx, &u); err != nil {\n\t\t\terrs = append(errs, fmt.Errorf(\"failed to create user %#q: %w\", u.Name, err))\n\t\t}\n\t}\n\tfor _, entry := range userData.WriteFiles {\n\t\tif err := writeFiles(ctx, entry); err != nil {\n\t\t\terrs = append(errs, fmt.Errorf(\"failed to write file for path %#q: %w\", entry.Path, err))\n\t\t}\n\t}\n\tif userData.ManageResolvConf && userData.ResolvConf != nil {\n\t\tif err = setResolvConf(ctx, userData.ResolvConf); err != nil {\n\t\t\terrs = append(errs, fmt.Errorf(\"failed to apply DNS configuration: %w\", err))\n\t\t}\n\t}\n\tif userData.CACerts != nil {\n\t\tlogrus.Warn(\"ca_certs is not implemented\")\n\t}\n\tif len(userData.BootCmd) > 0 {\n\t\tlogrus.Warn(\"bootcmd is not implemented\")\n\t}\n\treturn errors.Join(errs...)\n}\n\n// mountFSTabEntry mounts a filesystem based on the given fstab entry.\n// The format mimics Linux's convention.","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/guestagent/fakecloudinit/fakecloudinit_darwin.go#L108-L144","documentation":"Raised by processUserData when a `write_files:` entry from the user-data cannot be written. writeFiles validates the path and permissions, creates the parent directory, then writes the file; the wrapped error pinpoints which of those steps failed. The target path is included via %#q.","triggerScenarios":"An entry has empty `path`, a non-octal `permissions` string, the parent directory cannot be created (permission denied), the os.WriteFile itself fails, or the subsequent `chown <owner>` command fails when `owner` is set.","commonSituations":"Writing to a root-only location while running unprivileged, typo in the permissions (e.g. `rwxr-xr-x` instead of `0755`), or an owner spec that the chown command does not accept (user must exist).","solutions":["Read the wrapped error: it tells whether path, permissions, mkdir, write, or chown failed.","Ensure each write_files entry has a non-empty absolute `path`.","Specify permissions as an octal string like \"0644\", not symbolic.","Check that the agent has write access to the destination directory.","If `owner` is set, make sure the referenced user/group already exists before the write_files step."],"exampleFix":"// before (user-data)\nwrite_files:\n  - content: \"hello\"\n    path: /etc/motd\n    permissions: \"rw-r--r--\"\n// after\nwrite_files:\n  - content: \"hello\"\n    path: /etc/motd\n    permissions: \"0644\"","handlingStrategy":"validation","validationCode":"func validateWriteFiles(entries []cloudinittypes.WriteFile) error {\n  for i, e := range entries {\n    if e.Path == \"\" || !filepath.IsAbs(e.Path) { return fmt.Errorf(\"write_files[%d]: path must be absolute\", i) }\n    if e.Permissions != \"\" {\n      if _, err := strconv.ParseUint(e.Permissions, 8, 32); err != nil {\n        return fmt.Errorf(\"write_files[%d]: permissions %q not octal\", i, e.Permissions)\n      }\n    }\n  }\n  return nil\n}","typeGuard":"func isWritableEntry(e cloudinittypes.WriteFile) bool {\n  if e.Path == \"\" { return false }\n  if e.Permissions != \"\" { _, err := strconv.ParseUint(e.Permissions, 8, 32); return err == nil }\n  return true\n}","tryCatchPattern":"for _, entry := range userData.WriteFiles {\n  if err := writeFiles(ctx, entry); err != nil {\n    log.Errorf(\"write_files failed for %q: %v\", entry.Path, err)\n  }\n}","preventionTips":["Use octal permission strings like \"0644\", never symbolic modes.","Ensure the guestagent runs with privileges for root-owned destinations.","Set `owner` only to users that already exist at provisioning time.","Create custom parent directories explicitly if outside standard paths."],"tags":["macos","cloud-init","write-files","filesystem"],"backgroundTag":"file-write-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}