GoogleContainerTools/skaffold · error
yaml to json error: %w
Error message
yaml to json error: %w
What it means
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.
Source
Thrown at pkg/skaffold/kubernetes/manifest/filter.go:36
import (
"fmt"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
k8syaml "sigs.k8s.io/yaml"
)
// Filter returns the manifest list that match any of the given `GroupKindSelector` items
func (l *ManifestList) Filter(selectors ...GroupKindSelector) (ManifestList, error) {
if l == nil {
return nil, nil
}
var filtered ManifestList
for _, yByte := range *l {
// Convert yaml byte config to unstructured.Unstructured
jByte, err := k8syaml.YAMLToJSON(yByte)
if err != nil {
return nil, fmt.Errorf("yaml to json error: %w", err)
}
var obj unstructured.Unstructured
if err := obj.UnmarshalJSON(jByte); err != nil {
return nil, fmt.Errorf("unmarshaling config: %w", err)
}
gvk := obj.GroupVersionKind()
for _, w := range selectors {
if w.Matches(gvk.Group, gvk.Kind) {
filtered.Append(yByte)
}
}
}
return filtered, nil
}
// SelectResources returns the resources defined in the manifest list that match any of the given `GroupKindSelector` items
func (l *ManifestList) SelectResources(selectors ...GroupKindSelector) ([]unstructured.Unstructured, error) {
if l == nil {View on GitHub (pinned to a1189de023)
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
Example fix
// before (tab indentation -> YAML parse error) metadata: name: foo // after metadata: name: foo
Defensive patterns
Strategy: validation
Validate before calling
import "gopkg.in/yaml.v3"
func isParsableYAML(doc []byte) error {
var v interface{}
return yaml.Unmarshal(doc, &v)
}
// for each manifest in the list: if err := isParsableYAML(m); err != nil { fix before Filter } Type guard
func looksLikeK8sYAML(doc []byte) bool {
var m map[string]interface{}
if err := yaml.Unmarshal(doc, &m); err != nil || m == nil { return false }
_, hasKind := m["kind"]
return hasKind
} Try / catch
filtered, err := manifests.Selectors(selectors).Filter(...)
if err != nil && strings.Contains(err.Error(), "yaml to json error") {
// log wrapped cause (line/col), quarantine the bad manifest, continue
return fmt.Errorf("manifest is not valid YAML: %w", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- reading Kubernetes YAML: %w
- loading post-renderer result: %w
- loading manifests: %w
- DEPLOY_READ_MANIFEST_ERR
- parsing manifests file into manifest list object: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/dce5d35466c58797.
Report an issue: GitHub.