{"record":{"id":"11ddabfb77b75767","repo":"lima-vm/lima","slug":"the-yaml-is-invalid-saved-the-buffer-as-q-w","errorCode":null,"errorMessage":"the YAML is invalid, saved the buffer as %#q: %w","messagePattern":"the YAML is invalid, saved the buffer as %#q: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/edit.go","lineNumber":232,"sourceCode":"\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":214,"sourceCodeEnd":234,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/edit.go#L214-L234","documentation":"The normal \"rejected YAML\" error from `saveRejectedYAML`: the edited instance YAML failed lima's validation, but lima successfully saved the invalid buffer to `lima.REJECTED.yaml` in the current working directory so nothing is lost. The wrapped `%w` cause is the actual `limayaml.Validate` error describing which field is wrong.","triggerScenarios":"Any of `limactl edit`, `limactl clone`/`rename`, `limactl restart` (with re-edit), or `limactl edit --set <yq-expr>` producing a YAML that fails validation: unknown/removed fields, invalid values (bad arch, empty required field, conflicting mounts, invalid port forwards in the config).","commonSituations":"Hand-editing lima.yaml and introducing a typo or unsupported field; upgrading lima so a previously valid field was removed/renamed; a `--set` yq expression producing an invalid structure; copy-pasting a template with fields unsupported on the host.","solutions":["Read the wrapped cause at the end of the message; fix that specific field in the editor and retry `limactl edit`.","Inspect the saved `lima.REJECTED.yaml` in the current directory to see exactly what was rejected, then correct it.","Validate offline before applying: pipe the YAML through a minimal check or compare against `templates/` examples in the lima repo.","If a lima upgrade removed fields, migrate per release notes (e.g. move deprecated keys to their replacements)."],"exampleFix":"// before\nyaml:\n  cpus: \"4\"          # ok\n  arh: x86_64        # typo field -> validation fails\n\n// after\nyaml:\n  cpus: 4\n  arch: x86_64","handlingStrategy":"validation","validationCode":"// Validate the YAML shape yourself before submitting (Go, using lima's loader):\n_, err := limayaml.Load([]byte(newYAML), \"edited.yaml\")\nif err != nil {\n    return fmt.Errorf(\"edited YAML will be rejected: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := runEdit(inst); err != nil {\n    var verr *ValidationError // or match on the wrapped cause\n    if strings.Contains(err.Error(), \"saved the buffer as\") {\n        rejected, _ := os.ReadFile(\"lima.REJECTED.yaml\")\n        log.Printf(\"rejected YAML kept at lima.REJECTED.yaml (%d bytes); fix reported field and retry\", len(rejected))\n    }\n    return err\n}","preventionTips":["After a lima upgrade, check release notes for removed/renamed lima.yaml fields before editing existing instances.","Keep a backup: `cp ~/.lima/<inst>/lima.yaml ~/.lima/<inst>/lima.yaml.bak` before edits.","Test `--set` yq expressions against a copy of the YAML first; inspect the saved lima.REJECTED.yaml when a change is rejected."],"tags":["yaml","validation","config","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"}