{"record":{"id":"7098b6f788d3a48a","repo":"kubernetes/kops","slug":"error-parsing-yaml-v-7098b6","errorCode":null,"errorMessage":"error parsing yaml: %v","messagePattern":"error parsing yaml: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/kubemanifest/manifest.go","lineNumber":81,"sourceCode":"type ObjectList []*Object\n\n// LoadObjectsFrom parses multiple objects from a yaml file\nfunc LoadObjectsFrom(contents []byte) (ObjectList, error) {\n\tvar objects []*Object\n\n\tsections := text.SplitContentToSections(contents)\n\n\tfor _, section := range sections {\n\t\t// We need this so we don't error on a section that is empty / commented out\n\t\tif !hasYAMLContent(section) {\n\t\t\tcontinue\n\t\t}\n\n\t\tdata := make(map[string]interface{})\n\t\terr := yaml.Unmarshal(section, &data)\n\t\tif err != nil {\n\t\t\tklog.Infof(\"invalid YAML section: %s\", string(section))\n\t\t\treturn nil, fmt.Errorf(\"error parsing yaml: %v\", err)\n\t\t}\n\n\t\tobj := &Object{\n\t\t\t// bytes: section,\n\t\t\tdata: data,\n\t\t}\n\t\tobjects = append(objects, obj)\n\t}\n\n\treturn objects, nil\n}\n\n// hasYAMLContent determines if the byte slice has any content,\n// because yaml parsing gives an error if called with no content.\n// TODO: How does apimachinery avoid this problem?\nfunc hasYAMLContent(yamlData []byte) bool {\n\tfor _, line := range bytes.Split(yamlData, []byte(\"\\n\")) {\n\t\tl := bytes.TrimSpace(line)","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/kubemanifest/manifest.go#L63-L99","documentation":"LoadObjectsFrom splits a manifest file into YAML documents and unmarshals each section into a generic map. When a section is not valid YAML (or is not a mapping), it logs the offending section via klog and returns this error, aborting the load.","triggerScenarios":"Calling any of LoadObjectsFrom's callers (ParseAddons, Apply, Prune, List, RemapManifest, ParseClusterAddon) with a file containing malformed YAML syntax, tabs for indentation, or a document that unmarshals to a non-map value.","commonSituations":"Hand-edited addon manifests with indentation mistakes; tabs instead of spaces; duplicate keys; truncated files from failed downloads; passing a non-manifest file to the command.","solutions":["Fix the YAML syntax in the flagged section (the invalid section is printed just above the error in klog output)","Run `yamllint` or `kubectl apply --dry-run=client -f file.yaml` to pinpoint the line","Replace tabs with spaces and fix indentation/duplicate keys","Re-download/restore the manifest file if it was truncated or corrupted"],"exampleFix":"// before (manifest.yaml)\naddons:\n\t- name: foo  # tab indentation -> parse error\n// after\naddons:\n  - name: foo","handlingStrategy":"validation","validationCode":"func validateYAMLFile(path string) error {\n\tdata, err := os.ReadFile(path)\n\tif err != nil { return err }\n\tfor i, section := range bytes.Split(data, []byte(\"\\n---\")) {\n\t\tvar m map[string]interface{}\n\t\tif err := yaml.Unmarshal(section, &m); err != nil {\n\t\t\treturn fmt.Errorf(\"document %d invalid: %w\", i, err)\n\t\t}\n\t}\n\treturn nil\n}\n","typeGuard":null,"tryCatchPattern":"objs, err := kubemanifest.LoadObjectsFrom(data)\nif err != nil {\n\tif strings.Contains(err.Error(), \"error parsing yaml\") {\n\t\treturn fmt.Errorf(\"manifest file is not valid YAML; run yamllint on it: %w\", err)\n\t}\n\treturn err\n}\n","preventionTips":["Lint manifests with yamllint before use","Use spaces, never tabs, in YAML","Check for truncated downloads (file size, checksum)","Validate with `kubectl apply --dry-run=client -f`"],"tags":["yaml","parsing","manifest"],"backgroundTag":"invalid-yaml","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"}