{"record":{"id":"d3c05df053e452b9","repo":"lima-vm/lima","slug":"the-yaml-is-invalid-attempted-to-save-the-buffer","errorCode":null,"errorMessage":"the YAML is invalid, attempted to save the buffer as %#q but failed: %w","messagePattern":"the YAML is invalid, attempted to save the buffer as %#q but failed: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/edit.go","lineNumber":229,"sourceCode":"\nfunc askWhetherToStart(cmd *cobra.Command) (bool, error) {\n\tisTTY := uiutil.InputIsTTY(cmd.InOrStdin())\n\tif isTTY {\n\t\tmessage := \"Do you want to start the instance now? \"\n\t\treturn uiutil.Confirm(message, true)\n\t}\n\treturn false, nil\n}\n\nfunc editBashComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {\n\treturn bashCompleteInstanceNames(cmd)\n}\n\n// saveRejectedYAML writes the rejected config and returns an error.\nfunc saveRejectedYAML(y []byte, origErr error) error {\n\trejectedYAML := \"lima.REJECTED.yaml\"\n\tif writeErr := os.WriteFile(rejectedYAML, y, 0o644); writeErr != nil {\n\t\treturn fmt.Errorf(\"the YAML is invalid, attempted to save the buffer as %#q but failed: %w\", rejectedYAML, errors.Join(writeErr, origErr))\n\t}\n\t// TODO: may need to support editing the rejected YAML\n\treturn fmt.Errorf(\"the YAML is invalid, saved the buffer as %#q: %w\", rejectedYAML, origErr)\n}\n","sourceCodeStart":211,"sourceCodeEnd":234,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/edit.go#L211-L234","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (in non-writable dir)\n$ cd /etc && limactl edit myvm\nFATA ... the YAML is invalid, attempted to save the buffer as \"lima.REJECTED.yaml\" but failed: permission denied + field must be set\n\n// after\n$ cd ~ && limactl edit myvm   # writable cwd; rejected YAML can be saved","handlingStrategy":"validation","validationCode":"// Ensure the cwd is writable before running edit:\nif err := os.WriteFile(\".lima-write-test\", nil, 0o644); err != nil {\n    os.Chdir(homeDir()) // move to a writable directory\n} else {\n    os.Remove(\".lima-write-test\")\n}","typeGuard":null,"tryCatchPattern":"if err := runEdit(inst); err != nil {\n    if strings.Contains(err.Error(), \"attempted to save the buffer as\") {\n        // both write failure and validation failure are joined via errors.Join\n        for _, cause := range errors.Unwrap Multi(err) { ... }\n        // retry from a writable directory\n        return retryEditFromWritableDir(inst)\n    }\n    return err\n}","preventionTips":["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."],"tags":["yaml","validation","filesystem","cli"],"backgroundTag":"yaml-validation-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}