{"record":{"id":"9d42896761e5c671","repo":"kubernetes/kops","slug":"error-parsing-file-q-v-9d4289","errorCode":null,"errorMessage":"error parsing file %q: %v","messagePattern":"error parsing file %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/replace.go","lineNumber":112,"sourceCode":"\tfor _, f := range c.Filenames {\n\t\tvar contents []byte\n\t\tif f == \"-\" {\n\t\t\tcontents, err = ConsumeStdin()\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t} else {\n\t\t\tcontents, err = vfsContext.ReadFile(f)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error reading file %q: %v\", f, err)\n\t\t\t}\n\t\t}\n\t\tsections := text.SplitContentToSections(contents)\n\n\t\tfor _, section := range sections {\n\t\t\to, gvk, err := kopscodecs.Decode(section, nil)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error parsing file %q: %v\", f, err)\n\t\t\t}\n\n\t\t\tswitch v := o.(type) {\n\t\t\tcase *kopsapi.Cluster:\n\t\t\t\t{\n\t\t\t\t\t// Retrieve the current status of the cluster.  This will eventually be part of the cluster object.\n\t\t\t\t\tcloud, err := cloudup.BuildCloud(v)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\t\t\t\t\tstatus, err := cloud.FindClusterStatus(v)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\n\t\t\t\t\t// Check if the cluster exists already\n\t\t\t\t\tclusterName := v.Name\n\t\t\t\t\tcluster, err := clientset.GetCluster(ctx, clusterName)","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/replace.go#L94-L130","documentation":"After splitting the file into YAML/JSON sections, kops decodes each via kopscodecs.Decode. This error means a section is not valid YAML/JSON, is not a registered kops API type, or fails schema validation for the target group-version.","triggerScenarios":"Manifest with invalid YAML syntax (bad indentation, tabs); YAML that parses but whose kind/apiVersion is not a kops type (e.g. a Deployment); missing required fields; documents separated with a separator kops does not recognize; an apiVersion from an incompatible kops version.","commonSituations":"Hand-edited cluster.yaml with a syntax error; exporting a k8s workload manifest and passing it to `kops replace`; upgrading kops so an old apiVersion (e.g. kops/v1alpha2) is no longer accepted; copy-pasting YAML with tabs.","solutions":["Validate the YAML/JSON syntax (yamllint or `kubectl apply --dry-run=client` style parsing)","Ensure kind and apiVersion are supported kops types for your kops binary version","Run `kops replace --help` / check docs for the accepted schema; upgrade or regenerate the manifest with `kops get -o yaml`","Fix indentation (spaces, never tabs) and document separators (---)","Decode incrementally: split the file and parse each section to find the offending document"],"exampleFix":"// before (invalid)\nkind: Cluster\nmetadata:\n\tname: mycluster\n// after\nkind: Cluster\nmetadata:\n  name: mycluster","handlingStrategy":"validation","validationCode":"var raw interface{}\nif err := yaml.Unmarshal(contents, &raw); err != nil {\n    return fmt.Errorf(\"invalid YAML: %w\", err)\n}\n// Optionally assert kind is a supported kops type before calling replace.\nkind, _ := raw.(map[string]interface{})[\"kind\"].(string)\nsupported := map[string]bool{\"Cluster\": true, \"InstanceGroup\": true}\nif !supported[kind] {\n    return fmt.Errorf(\"unsupported kind for kops replace: %s\", kind)\n}","typeGuard":"func isKopsManifestKind(kind string) bool {\n    switch kind {\n    case \"Cluster\", \"InstanceGroup\":\n        return true\n    }\n    return false\n}","tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"no kind\") || strings.Contains(err.Error(), \"cannot unmarshal\") {\n        // schema/parse problem: log file + line, fix manifest\n    }\n    return err\n}","preventionTips":["Lint manifests with yamllint before running kops","Use spaces, never tabs, in YAML","Generate manifests with `kops get -o yaml` to guarantee valid schema","Pin kops CLI and manifest apiVersion to compatible versions"],"tags":["yaml","parsing","schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}