{"record":{"id":"a998a9ea38cd5f0e","repo":"GoogleContainerTools/skaffold","slug":"reading-kubernetes-yaml-w","errorCode":null,"errorMessage":"reading Kubernetes YAML: %w","messagePattern":"reading Kubernetes YAML: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/kubernetes/manifest/namespaces.go","lineNumber":98,"sourceCode":"\t\tif ns := strings.TrimSpace(nsString); ns != \"\" {\n\t\t\tr.namespaces[ns] = true\n\t\t}\n\t}\n\treturn false\n}\n\n// SetNamespace sets labels to a list of Kubernetes manifests if they are not set.\n// Returns error if any manifest in the list has namespace set.\nfunc (l *ManifestList) SetNamespace(namespace string, rs ResourceSelector) (ManifestList, error) {\n\tif namespace == \"\" {\n\t\tnamespace = defaultNamespace\n\t}\n\tvar updated ManifestList\n\tfor _, item := range *l {\n\t\tupdatedManifest := item\n\t\tm := make(map[string]interface{})\n\t\tif err := yaml.Unmarshal(item, &m); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"reading Kubernetes YAML: %w\", err)\n\t\t}\n\t\tif shouldTransformManifest(m, rs) {\n\t\t\tvar errU error\n\t\t\tif errU = addOrUpdateNamespace(m, namespace); errU != nil {\n\t\t\t\treturn nil, errU\n\t\t\t}\n\t\t\tupdatedManifest, errU = yaml.Marshal(m)\n\t\t\tif errU != nil {\n\t\t\t\treturn nil, nsSettingErr(errU)\n\t\t\t}\n\t\t}\n\t\tupdated = append(updated, updatedManifest)\n\t}\n\n\tlog.Entry(context.TODO()).Debugln(\"manifests set with namespace\", updated.String())\n\treturn updated, nil\n}\n","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/kubernetes/manifest/namespaces.go#L80-L116","documentation":"SetNamespace unmarshals each manifest item into a generic map (map[string]interface{}) with gopkg.in/yaml.v3 before conditionally adding the namespace. If a manifest is not valid YAML, yaml.Unmarshal fails and the error is wrapped as 'reading Kubernetes YAML'.","triggerScenarios":"Calling ManifestList.SetNamespace (via BaseTransform) when any item in the ManifestList is malformed YAML — syntax errors, or content that cannot unmarshal into a map (e.g. a top-level sequence or scalar).","commonSituations":"Templates or Helm output producing invalid YAML, manifests whose top level is a list instead of an object, files with duplicate keys or bad types (e.g. 'replicas: abc' where the map decode is fine but downstream steps then fail).","solutions":["Fix the YAML syntax error named in the wrapped cause (yaml.v3 reports line/column)","Ensure each document is a top-level mapping (object), not a list or scalar","Run a YAML parser/linter over each manifest to catch the offending file before transformation","Regenerate the manifest list from the render step and confirm its output parses"],"exampleFix":"// before: top-level list cannot unmarshal into map[string]interface{}\n- apiVersion: v1\n  kind: Service\n// after\napiVersion: v1\nkind: Service","handlingStrategy":"validation","validationCode":"import \"gopkg.in/yaml.v3\"\nfunc isYAMLMap(item []byte) error {\n  var m map[string]interface{}\n  if err := yaml.Unmarshal(item, &m); err != nil { return err }\n  if m == nil { return errors.New(\"empty or non-mapping document\") }\n  return nil\n}\n// check each item before SetNamespace","typeGuard":"func isDocMapping(item []byte) bool {\n  var m map[string]interface{}\n  return yaml.Unmarshal(item, &m) == nil && m != nil\n}","tryCatchPattern":"updated, err := manifests.Transform(rs, transform.SetNamespace(ns))\nif err != nil && strings.Contains(err.Error(), \"reading Kubernetes YAML\") {\n  // find the malformed item, fix or drop it, then retry the transform\n  return fmt.Errorf(\"manifest unreadable as YAML: %w\", err)\n}","preventionTips":["Ensure each manifest item is a top-level YAML mapping before transforms","Lint manifests (yamllint) in pre-commit and CI","Avoid tabs and duplicate keys in manifest sources","Dry-run renders with 'skaffold render' to catch unreadable manifests early"],"tags":["yaml","manifest","parsing"],"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"}