GoogleContainerTools/skaffold · critical
unable to parse YAML: %w
Error message
unable to parse YAML: %w
What it means
removeYamlAnchors parses the config YAML document-by-document to strip top-level keys starting with a dot. If any document fails to decode into a generic map, this wrapped error is returned from ParseConfig.
Source
Thrown at pkg/skaffold/schema/versions.go:298
return factories, nil
}
// removeYamlAnchors removes all top-level keys starting with `.` from the input stream so they can be used as YAML anchors
func removeYamlAnchors(buf []byte) ([]byte, error) {
in := bytes.NewReader(buf)
var out bytes.Buffer
decoder := yaml.NewDecoder(in)
decoder.KnownFields(true)
encoder := yaml.NewEncoder(&out)
for {
parsed := make(map[string]interface{})
err := decoder.Decode(parsed)
if err == io.EOF {
break
}
if err != nil {
return nil, fmt.Errorf("unable to parse YAML: %w", err)
}
for field := range parsed {
if strings.HasPrefix(field, ".") {
delete(parsed, field)
}
}
err = encoder.Encode(parsed)
if err != nil {
return nil, err
}
}
err := encoder.Close()
if err != nil {
return nil, err
}
return out.Bytes(), nil
}
View on GitHub (pinned to a1189de023)
Solutions
- Ensure every YAML document in the file is a mapping (key: value form), not a bare scalar or list
- Run yamllint to locate syntax errors and fix them
- Check the wrapped cause (%w) for the exact failing document/line
- Remove stray '---' separators or empty/broken trailing documents
Example fix
# before (non-mapping document) apiVersion: skaffold/v4beta7 kind: Config --- just a scalar # after apiVersion: skaffold/v4beta7 kind: Config
Defensive patterns
Strategy: validation
Validate before calling
docs := strings.Split(string(data), "\n---")
for _, d := range docs {
var m map[string]interface{}
if err := yaml.Unmarshal([]byte(d), &m); err != nil || m == nil {
return fmt.Errorf("YAML document is not a valid mapping: %w", err)
}
} Try / catch
_, err := schema.ParseConfig(cfgPath)
if err != nil {
if strings.Contains(err.Error(), "unable to parse YAML") {
// run yamllint and show the wrapped cause to the user
}
return err
} Prevention
- Keep every document in skaffold.yaml a mapping
- Avoid stray or trailing '---' separators
- Run a YAML linter on every config change
When it happens
Trigger: Calling ParseConfig on a YAML file where a document is syntactically invalid or is not decodable as map[string]interface{} (e.g. a bare scalar or sequence document mixed into the file).
Common situations: A skaffold.yaml containing malformed segments; multi-document files where one document is not a mapping (e.g. a stray '---' followed by a scalar); syntax errors like unclosed quotes.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- unable to re-marshal YAML without dotted keys: %w
- parsing api version: %w
- read skaffold config: %w
- `apply` requires at least one manifest argument
- `exec` requires exactly one action to execute
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/3a745915f84e700d.
Report an issue: GitHub.