lima-vm/lima · error
the YAML is invalid, attempted to save the buffer as %#q but
Error message
the YAML is invalid, attempted to save the buffer as %#q but failed: %w
What it means
Thrown by `saveRejectedYAML` when the edited instance YAML failed validation AND lima also failed to write the rejected buffer to `lima.REJECTED.yaml` in the current directory. The write error and the original validation error are joined with `errors.Join` so both causes are visible. Lima saves rejected YAML so users can recover their edits, and this error indicates even that recovery dump failed.
Source
Thrown at cmd/limactl/edit.go:229
func askWhetherToStart(cmd *cobra.Command) (bool, error) {
isTTY := uiutil.InputIsTTY(cmd.InOrStdin())
if isTTY {
message := "Do you want to start the instance now? "
return uiutil.Confirm(message, true)
}
return false, nil
}
func editBashComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return bashCompleteInstanceNames(cmd)
}
// saveRejectedYAML writes the rejected config and returns an error.
func saveRejectedYAML(y []byte, origErr error) error {
rejectedYAML := "lima.REJECTED.yaml"
if writeErr := os.WriteFile(rejectedYAML, y, 0o644); writeErr != nil {
return fmt.Errorf("the YAML is invalid, attempted to save the buffer as %#q but failed: %w", rejectedYAML, errors.Join(writeErr, origErr))
}
// TODO: may need to support editing the rejected YAML
return fmt.Errorf("the YAML is invalid, saved the buffer as %#q: %w", rejectedYAML, origErr)
}
View on GitHub (pinned to dd909d0973)
Solutions
- Fix the write problem: run limactl from a writable directory (`cd ~`) or `sudo chown`/remove the stale `lima.REJECTED.yaml`.
- Free disk space if the disk is full, then retry.
- Read the joined cause at the end of the message to also fix the underlying YAML validation error (invalid field, bad value) and re-edit.
- Recover manually: re-run the edit, keep a copy of the YAML in a temp file (`limactl edit <inst>` uses $EDITOR; or copy the instance's lima.yaml from ~/.lima/<inst>/lima.yaml) before editing.
Example fix
// before (in non-writable dir) $ cd /etc && limactl edit myvm FATA ... the YAML is invalid, attempted to save the buffer as "lima.REJECTED.yaml" but failed: permission denied + field must be set // after $ cd ~ && limactl edit myvm # writable cwd; rejected YAML can be saved
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the cwd is writable before running edit:
if err := os.WriteFile(".lima-write-test", nil, 0o644); err != nil {
os.Chdir(homeDir()) // move to a writable directory
} else {
os.Remove(".lima-write-test")
} Try / catch
if err := runEdit(inst); err != nil {
if strings.Contains(err.Error(), "attempted to save the buffer as") {
// both write failure and validation failure are joined via errors.Join
for _, cause := range errors.Unwrap Multi(err) { ... }
// retry from a writable directory
return retryEditFromWritableDir(inst)
}
return err
} Prevention
- Run limactl from a user-writable directory (e.g. $HOME), never from /etc or other system dirs.
- Remove stale root-owned lima.REJECTED.yaml files after previous sudo runs.
- Monitor disk space on the host where limactl runs.
When it happens
Trigger: Calling `limactl edit`, `limactl clone`/`rename`, `limactl restart --edit`, or applying a yq expression, where the new YAML fails `limayaml.Validate` and `os.WriteFile("lima.REJECTED.yaml", ...)` fails due to filesystem permission or disk issues.
Common situations: Read-only current working directory or running from a directory the user cannot write to; disk full; SELinux/AppArmor denying writes; the file lima.REJECTED.yaml exists with root ownership from a previous root-run attempt.
Related errors
- the YAML is invalid, saved the buffer as %#q: %w
- failed to validate YAML file %#q: %w
- disk format %#q not supported, use `qcow2` or `raw` instead
- invalid port forward format %#q, expected HOST:GUEST or HOST
- invalid port forward format %#q, expected HOST:GUEST
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/d3c05df053e452b9.
Report an issue: GitHub.