{"record":{"id":"dce5d35466c58797","repo":"GoogleContainerTools/skaffold","slug":"yaml-to-json-error-w","errorCode":null,"errorMessage":"yaml to json error: %w","messagePattern":"yaml to json error: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/kubernetes/manifest/filter.go","lineNumber":36,"sourceCode":"\nimport (\n\t\"fmt\"\n\n\t\"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured\"\n\tk8syaml \"sigs.k8s.io/yaml\"\n)\n\n// Filter returns the manifest list that match any of the given `GroupKindSelector` items\nfunc (l *ManifestList) Filter(selectors ...GroupKindSelector) (ManifestList, error) {\n\tif l == nil {\n\t\treturn nil, nil\n\t}\n\tvar filtered ManifestList\n\tfor _, yByte := range *l {\n\t\t// Convert yaml byte config to unstructured.Unstructured\n\t\tjByte, err := k8syaml.YAMLToJSON(yByte)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"yaml to json error: %w\", err)\n\t\t}\n\t\tvar obj unstructured.Unstructured\n\t\tif err := obj.UnmarshalJSON(jByte); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"unmarshaling config: %w\", err)\n\t\t}\n\t\tgvk := obj.GroupVersionKind()\n\t\tfor _, w := range selectors {\n\t\t\tif w.Matches(gvk.Group, gvk.Kind) {\n\t\t\t\tfiltered.Append(yByte)\n\t\t\t}\n\t\t}\n\t}\n\treturn filtered, nil\n}\n\n// SelectResources returns the resources defined in the manifest list that match any of the given `GroupKindSelector` items\nfunc (l *ManifestList) SelectResources(selectors ...GroupKindSelector) ([]unstructured.Unstructured, error) {\n\tif l == nil {","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/kubernetes/manifest/filter.go#L18-L54","documentation":"ManifestList.Filter converts each YAML manifest to JSON with sigs.k8s.io/yaml (YAMLToJSON) before matching selectors. If a manifest document is not parseable YAML, the conversion fails and the error is wrapped as 'yaml to json error'. The library cannot match Group/Kind on invalid input, so it fails fast.","triggerScenarios":"Calling ManifestList.Filter with a selector list when any element of the ManifestList contains malformed YAML (bad indentation, tabs, duplicate keys, invalid types) or non-UTF8 bytes.","commonSituations":"Manifests generated by templates producing broken YAML, files with tab indentation, truncated multi-document output from a previous render step, or binary/corrupted content passed as a manifest.","solutions":["Run 'kubectl apply --dry-run=client' or a YAML linter (yamllint) on each manifest to find the malformed document","Fix the YAML syntax error reported by the wrapped %w cause (it names line/column)","If manifests come from another tool, re-render them and check that tool's output for corruption","Validate with 'skaffold render' locally before filtering in the pipeline"],"exampleFix":"// before (tab indentation -> YAML parse error)\nmetadata:\n\tname: foo\n// after\nmetadata:\n  name: foo","handlingStrategy":"validation","validationCode":"import \"gopkg.in/yaml.v3\"\nfunc isParsableYAML(doc []byte) error {\n  var v interface{}\n  return yaml.Unmarshal(doc, &v)\n}\n// for each manifest in the list: if err := isParsableYAML(m); err != nil { fix before Filter }","typeGuard":"func looksLikeK8sYAML(doc []byte) bool {\n  var m map[string]interface{}\n  if err := yaml.Unmarshal(doc, &m); err != nil || m == nil { return false }\n  _, hasKind := m[\"kind\"]\n  return hasKind\n}","tryCatchPattern":"filtered, err := manifests.Selectors(selectors).Filter(...)\nif err != nil && strings.Contains(err.Error(), \"yaml to json error\") {\n  // log wrapped cause (line/col), quarantine the bad manifest, continue\n  return fmt.Errorf(\"manifest is not valid YAML: %w\", err)\n}","preventionTips":["Run yamllint or 'kubectl apply --dry-run=client' on manifests before feeding them to skaffold","Ban tab indentation in manifest repos (lint rule / pre-commit hook)","Check output of template/Helm render steps for truncated or partial files","Keep manifests UTF-8 encoded and free of smart quotes"],"tags":["yaml","json","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"}