{"record":{"id":"6056ff33508432f3","repo":"kubernetes/kops","slug":"error-parsing-yaml-v","errorCode":null,"errorMessage":"error parsing yaml: %v","messagePattern":"error parsing yaml: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/create_instancegroup.go","lineNumber":278,"sourceCode":"\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\text := \"yaml\"\n\n\t\t// launch the editor\n\t\tedited, file, err := edit.LaunchTempFile(fmt.Sprintf(\"%s-edit-\", filepath.Base(os.Args[0])), ext, bytes.NewReader(raw))\n\t\tdefer func() {\n\t\t\tif file != \"\" {\n\t\t\t\ttry.RemoveFile(file)\n\t\t\t}\n\t\t}()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error launching editor: %v\", err)\n\t\t}\n\n\t\tobj, _, err := kopscodecs.Decode(edited, nil)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error parsing yaml: %v\", err)\n\t\t}\n\t\tgroup, ok := obj.(*kopsapi.InstanceGroup)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"unexpected object type: %T\", obj)\n\t\t}\n\n\t\terr = validation.CrossValidateInstanceGroup(group, cluster, cloud, true).ToAggregate()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tig = group\n\t}\n\n\t_, err = clientset.InstanceGroupsFor(cluster).Create(ctx, ig, metav1.CreateOptions{})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error storing InstanceGroup: %v\", err)\n\t}","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/create_instancegroup.go#L260-L296","documentation":"After the editor closes, kOps passes the edited bytes to kopscodecs.Decode to parse them back into a typed API object. If the edited content is not valid YAML, or is valid YAML but not a decodable kops API object, this error wraps the decoder failure.","triggerScenarios":"Editing the InstanceGroup YAML in the editor and introducing invalid YAML (bad indentation, tabs, stray characters), deleting required fields, or pasting non-YAML content into the buffer before saving.","commonSituations":"Editor converts indentation to tabs (YAML forbids tabs); smart-quote autocorrect from GUI editors; accidental truncation of the file; pasting JSON with syntax errors; editor saves a lockfile-suffixed or partial file.","solutions":["Fix the YAML syntax reported by the wrapped decoder error (check line/column in the message)","Replace tab characters with spaces for indentation","Re-run with --edit=false and edit the file with a proper YAML validator/linter (yamllint)","Restore the original structure: keep apiVersion, kind: InstanceGroup, metadata, and spec intact","Validate the YAML locally before saving, e.g. `python -c 'import yaml,sys; yaml.safe_load(sys.stdin)' < file`"],"exampleFix":"// before (in editor)\nspec:\n\tmachineType: n1-standard-1\n// after\nspec:\n  machineType: n1-standard-1","handlingStrategy":"validation","validationCode":"# validate the edited YAML before saving in the editor\nyamllint ig.yaml || python3 -c 'import yaml,sys; yaml.safe_load(open(\"ig.yaml\"))'","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"error parsing yaml\") {\n\t// re-open editor or restore original template and re-edit carefully with spaces\n}","preventionTips":["Configure the editor to expand tabs to spaces","Run yamllint or a schema validator on the manifest before saving","Do not delete apiVersion/kind/metadata blocks while editing","Avoid GUI autocorrect/smart quotes in config files"],"tags":["yaml","parsing","cli"],"backgroundTag":"yaml-parse-error","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}