{"record":{"id":"df020880eac5acef","repo":"kubernetes/kops","slug":"error-parsing-instancegroup-v","errorCode":null,"errorMessage":"error parsing InstanceGroup: %v","messagePattern":"error parsing InstanceGroup: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/edit_instancegroup.go","lineNumber":229,"sourceCode":"\t\tif bytes.Equal(stripComments(raw), stripComments(edited)) {\n\t\t\ttry.RemoveFile(file)\n\t\t\tfmt.Fprintln(out, \"Edit cancelled: no changes made.\")\n\t\t\treturn nil\n\t\t}\n\n\t\tlines, err := hasLines(bytes.NewBuffer(edited))\n\t\tif err != nil {\n\t\t\treturn preservedFile(err, file, out)\n\t\t}\n\t\tif !lines {\n\t\t\ttry.RemoveFile(file)\n\t\t\tfmt.Fprintln(out, \"Edit cancelled: saved file was empty.\")\n\t\t\treturn nil\n\t\t}\n\n\t\tnewObj, _, err := kopscodecs.Decode(edited, nil)\n\t\tif err != nil {\n\t\t\treturn preservedFile(fmt.Errorf(\"error parsing InstanceGroup: %v\", err), file, out)\n\t\t}\n\n\t\tnewGroup, ok := newObj.(*api.InstanceGroup)\n\t\tif !ok {\n\t\t\tresults = editResults{\n\t\t\t\tfile: file,\n\t\t\t}\n\t\t\tresults.header.addError(fmt.Sprintf(\"object was not of expected type: %T\", newObj))\n\t\t\tcontainsError = true\n\t\t\tcontinue\n\t\t}\n\n\t\textraFields, err := edit.HasExtraFields(string(edited))\n\t\tif err != nil {\n\t\t\tresults = editResults{\n\t\t\t\tfile: file,\n\t\t\t}\n\t\t\tresults.header.addError(fmt.Sprintf(\"error checking for extra fields: %v\", err))","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/edit_instancegroup.go#L211-L247","documentation":"After the editor closes, kops decodes the edited buffer with kopscodecs.Decode into a typed object. Any YAML/JSON syntax error, unknown field, wrong kind, or missing apiVersion/kind produces \"error parsing InstanceGroup\". The temp file is preserved so the bad content is not lost.","triggerScenarios":"Saving `kops edit instancegroup` output with malformed YAML (bad indentation, tabs, duplicate keys), a stripped apiVersion: kops.k8s.io/v1alpha2 / kind: InstanceGroup header, or a field that fails schema deserialization.","commonSituations":"Manual edits breaking YAML indentation; editor inserting tabs; accidentally deleting the header comments containing kind/apiVersion; pasting a Cluster manifest instead of an InstanceGroup.","solutions":["Fix the syntax/structure error reported in the wrapped %v (line/column is usually included); the preserved file path is printed — reopen and fix it","Restore the header comments: apiVersion: kops.k8s.io/v1alpha2 and kind: InstanceGroup plus metadata.name","Validate offline first: run the edited content through `kops get instancegroups -o yaml` round-trip or yamlfmt","Paste the file into a YAML linter to find indentation/tab issues"],"exampleFix":"// before (broken)\nmetadata:\n  name: nodes\nspec:\n machineType: t3.medium  # bad indent\n// after\nmetadata:\n  name: nodes\nspec:\n  machineType: t3.medium","handlingStrategy":"validation","validationCode":"func validInstanceGroupYAML(b []byte) error {\n    var m map[string]interface{}\n    if err := yaml.Unmarshal(b, &m); err != nil {\n        return fmt.Errorf(\"invalid YAML: %w\", err)\n    }\n    if m[\"kind\"] != \"InstanceGroup\" || m[\"apiVersion\"] != \"kops.k8s.io/v1alpha2\" {\n        return errors.New(\"missing kind: InstanceGroup / apiVersion header\")\n    }\n    return nil\n}","typeGuard":"obj, _, err := kopscodecs.Decode(edited, nil)\nig, ok := obj.(*api.InstanceGroup)\nif !ok || err != nil {\n    return fmt.Errorf(\"not a valid InstanceGroup: %v\", err)\n}","tryCatchPattern":"if err := runEdit(); err != nil {\n    var perr *yaml.TypeError\n    if errors.As(err, &perr) || strings.Contains(err.Error(), \"error parsing InstanceGroup\") {\n        // reopen the preserved temp file and fix the reported line/column\n    }\n}","preventionTips":["Never delete the header comments carrying apiVersion/kind in the edit buffer","Use spaces, never tabs, in YAML","Lint the file with a YAML parser before saving","Round-trip with `kops get instancegroup <name> -o yaml` to see the canonical shape"],"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"}