lima-vm/lima · error
path is required for write_files entry
Error message
path is required for write_files entry
What it means
A `write_files` cloud-init entry was supplied without the mandatory `path` field. fakecloudinit's writeFiles requires an absolute destination path before it can create parent directories and write content, so it fails fast with this validation error instead of guessing a location.
Source
Thrown at pkg/guestagent/fakecloudinit/fakecloudinit_darwin.go:341
}
if err := os.MkdirAll("/etc/sudoers.d", 0o700); err != nil {
return fmt.Errorf("failed to create /etc/sudoers.d directory: %w", err)
}
sudoersPath := "/etc/sudoers.d/90-cloud-init-users"
f, err := os.OpenFile(sudoersPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o400)
if err != nil {
return fmt.Errorf("failed to open sudoers file %#q: %w", sudoersPath, err)
}
if _, err = fmt.Fprintf(f, "%s %s\n", userName, sudo); err != nil {
_ = f.Close()
return fmt.Errorf("failed to write to sudoers file %#q for user %#q: %w", sudoersPath, userName, err)
}
return f.Close()
}
func writeFiles(ctx context.Context, entry cloudinittypes.WriteFile) error {
if entry.Path == "" {
return errors.New("path is required for write_files entry")
}
perm := os.FileMode(0o644)
if entry.Permissions != "" {
p, err := strconv.ParseUint(entry.Permissions, 8, 32)
if err != nil {
return fmt.Errorf("invalid permissions %#q for path %#q: %w", entry.Permissions, entry.Path, err)
}
perm = os.FileMode(p)
}
if err := os.MkdirAll(filepath.Dir(entry.Path), 0o755); err != nil {
return fmt.Errorf("failed to create parent directory for path %#q: %w", entry.Path, err)
}
if err := os.WriteFile(entry.Path, []byte(entry.Content), perm); err != nil {
return fmt.Errorf("failed to write file for path %#q: %w", entry.Path, err)
}
if entry.Owner != "" {
cmd := exec.CommandContext(ctx, "chown", entry.Owner, entry.Path)
logrus.Infof("Executing command: %v", cmd.Args)View on GitHub (pinned to dd909d0973)
Solutions
- Add a `path` (absolute) to every write_files entry in user-data
- Fix YAML indentation so `path` is inside the same list item as `content`
- Check template expansion did not leave the path empty
- Validate the user-data YAML structure before starting the instance
Example fix
# before
write_files:
- content: |
hello
# after
write_files:
- path: /etc/hello.conf
content: |
hello Defensive patterns
Strategy: validation
Validate before calling
func validateWriteFiles(entries []cloudinittypes.WriteFile) error {
for i, e := range entries {
if e.Path == "" {
return fmt.Errorf("write_files[%d]: path is required", i)
}
if !filepath.IsAbs(e.Path) {
return fmt.Errorf("write_files[%d]: path %q must be absolute", i, e.Path)
}
}
return nil
} Type guard
func hasPath(e cloudinittypes.WriteFile) bool {
return strings.TrimSpace(e.Path) != ""
} Try / catch
if err := processUserData(ctx, data); err != nil {
if strings.Contains(err.Error(), "path is required for write_files") {
log.Printf("user-data write_files entry missing path: %v", err)
}
} Prevention
- Always specify an absolute `path` for each write_files entry
- Check YAML indentation so `path` sits inside the same list item
- Validate user-data YAML (e.g. with yamllint or cloud-init schema tools) before starting the instance
When it happens
Trigger: processUserData iterates the user-data `write_files` list and an entry has `path: ""` or the field omitted. Also caused by YAML indentation mistakes that produce an entry object without a path key.
Common situations: Copy-pasted write_files entries missing `path`; wrong YAML indentation placing `path` outside the entry mapping; templating that leaves `${PATH}`-style placeholders unexpanded, yielding an empty value.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- the YAML is invalid, attempted to save the buffer as %#q but
- the YAML is invalid, saved the buffer as %#q: %w
- failed to validate YAML file %#q: %w
- failed to enable SSHD: %w
- invalid fstab entry: expected 6 fields, got %d: %v
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/7ce625b126d0ad6c.
Report an issue: GitHub.