{"record":{"id":"689785c7502d91ba","repo":"GoogleContainerTools/skaffold","slug":"reading-kubernetes-yaml-w-689785","errorCode":null,"errorMessage":"reading Kubernetes YAML: %w","messagePattern":"reading Kubernetes YAML: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/kubernetes/util.go","lineNumber":103,"sourceCode":"\t}\n\tdefer f.Close()\n\n\tr := k8syaml.NewYAMLReader(bufio.NewReader(f))\n\n\tvar k8sObjects []yamlObject\n\n\tfor {\n\t\tdoc, err := r.Read()\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"reading config file: %w\", err)\n\t\t}\n\n\t\tobj := make(yamlObject)\n\t\tif err := yaml.Unmarshal(doc, &obj); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"reading Kubernetes YAML: %w\", err)\n\t\t}\n\n\t\tif !hasRequiredK8sManifestFields(obj) {\n\t\t\tcontinue\n\t\t}\n\n\t\tk8sObjects = append(k8sObjects, obj)\n\t}\n\tif len(k8sObjects) == 0 {\n\t\treturn nil, errors.New(\"no valid Kubernetes objects decoded\")\n\t}\n\treturn k8sObjects, nil\n}\n\nfunc hasRequiredK8sManifestFields(doc map[string]interface{}) bool {\n\tfor _, field := range requiredFields {\n\t\tif _, ok := doc[field]; !ok {\n\t\t\tlog.Entry(context.TODO()).Debugf(\"%s not present in yaml, continuing\", field)","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/kubernetes/util.go#L85-L121","documentation":"A YAML document was read successfully but yaml.Unmarshal into the generic yamlObject map failed, wrapped as 'reading Kubernetes YAML: %w'. This means the document is syntactically invalid YAML or has a structure that cannot decode into a map (e.g. a top-level list or scalar).","triggerScenarios":"A manifest file contains malformed YAML (bad indentation, tabs, duplicate keys with strict decoding, stray characters) or a document whose root is not a mapping, passed to ParseKubernetesObjects via validateManifests/IsKubernetesManifest/ParseImagesFromKubernetesYaml.","commonSituations":"Hand-edited manifests with tab indentation; copied YAML that lost indentation; a multi-doc file where one doc is `--- [1,2,3]`; unescaped special characters like ':' or '@' in values.","solutions":["Validate the YAML: `yamllint <file>` or `kubectl apply --dry-run=client -f <file>` to see the exact line/column","Replace tabs with spaces and fix indentation at the reported line","Ensure every document in the file starts with a mapping (key: value), not a list or scalar","Quote values containing special characters (':', '{', '}', '#', '@')"],"exampleFix":"// before\ncontainers:\n\t- name: app\n// after\ncontainers:\n  - name: app","handlingStrategy":"validation","validationCode":"// lint YAML before handing it to skaffold\nfunc lintYAML(path string) error {\n    data, err := os.ReadFile(path)\n    if err != nil {\n        return err\n    }\n    for i, doc := range strings.Split(string(data), \"\\n---\") {\n        var m map[string]interface{}\n        if err := yaml.Unmarshal([]byte(doc), &m); err != nil {\n            return fmt.Errorf(\"%s doc %d: %w\", path, i, err)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if _, err := kubernetes.ParseKubernetesObjects(path); err != nil {\n    var yamlErr *yaml.TypeError\n    if errors.As(err, &yamlErr) || strings.Contains(err.Error(), \"reading Kubernetes YAML\") {\n        return fmt.Errorf(\"invalid YAML in %s, run yamllint: %w\", path, err)\n    }\n    return err\n}","preventionTips":["Run yamllint or `kubectl apply --dry-run=client -f` in CI on all manifests","Never use tabs in YAML; configure editors to insert spaces","Quote values containing ':', '{', '}', '#', '@'","Ensure every document in a multi-doc file has a mapping root"],"tags":["kubernetes","yaml","parse-error"],"backgroundTag":"yaml-parse-error","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}