{"record":{"id":"5e2d2c3aa4b66eab","repo":"kubernetes/kops","slug":"unexpected-object-type-t","errorCode":null,"errorMessage":"unexpected object type: %T","messagePattern":"unexpected object type: %T","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/create_instancegroup.go","lineNumber":282,"sourceCode":"\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}\n\n\treturn nil\n}\n","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/create_instancegroup.go#L264-L300","documentation":"kopscodecs.Decode returns a runtime.Object; the command asserts it is specifically a *kopsapi.InstanceGroup. If the user changed `kind` in the editor (or the decoder produced a different type), the type assertion fails and kOps reports the actual Go type with %T so the user can see what was decoded instead.","triggerScenarios":"Editing the YAML and changing `kind: InstanceGroup` to another kind (e.g. Cluster, ClusterConfiguration, or a typo like Instancegroup), causing the codec to decode into a different registered type.","commonSituations":"Hand-editing kind/apiVersion fields; pasting a different kops object into the editor buffer; case mistakes in the kind name; using an apiVersion/group that maps to another type.","solutions":["Restore `kind: InstanceGroup` (exact case) and the correct apiVersion (kops.k8s.io/v1alpha2 or current) in the edited YAML","Do not paste other object types into the editor; edit only spec fields","Re-run with --edit=false if editing is not needed","Check the %T in the error to see which type was actually decoded and correct the manifest accordingly"],"exampleFix":"// before\nkind: Cluster\nmetadata:\n  name: nodes\n// after\nkind: InstanceGroup\nmetadata:\n  name: nodes","handlingStrategy":"type-guard","validationCode":"# ensure kind is untouched before saving\nhead -n 5 ig.yaml  # confirm 'kind: InstanceGroup' is present and unmodified","typeGuard":"group, ok := obj.(*kopsapi.InstanceGroup)\nif !ok { return fmt.Errorf(\"unexpected object type: %T\", obj) }","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"unexpected object type\") {\n\t// re-edit and restore kind: InstanceGroup with correct apiVersion\n}","preventionTips":["Never edit the kind or apiVersion lines in the editor","Copy-paste only spec values, not whole manifests of other types","Keep kind capitalization exactly 'InstanceGroup'"],"tags":["yaml","type-assertion","cli"],"backgroundTag":"unexpected-object-type","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"}