GoogleContainerTools/skaffold · error
unable to parse YAML: %w
Error message
unable to parse YAML: %w
What it means
inspect helpers read a skaffold.yaml file and decode each YAML document into a yamlv3.Node to build a config set. If the YAML decoder fails on malformed YAML (bad indentation, duplicate keys, invalid syntax), the error is wrapped as "unable to parse YAML: %w". The file cannot be inspected or modified until it is valid YAML.
Source
Thrown at pkg/skaffold/inspect/helper.go:71
}
func marshalConfigSetForFile(filename string, cfgs parser.SkaffoldConfigSet) error {
buf, err := ReadFileFunc(filename)
if err != nil {
return sErrors.ConfigParsingError(err)
}
in := bytes.NewReader(buf)
decoder := yamlv3.NewDecoder(in)
decoder.KnownFields(true)
var sl []interface{}
for {
var parsed yamlv3.Node
err := decoder.Decode(&parsed)
if err == io.EOF {
break
}
if err != nil {
return fmt.Errorf("unable to parse YAML: %w", err)
}
// parsed content is a document so the `Content` slice has exactly one element
sl = append(sl, parsed.Content[0])
}
for i, cfg := range cfgs {
sl[cfg.SourceIndex] = cfgs[i].SkaffoldConfig
}
newCfgs, err := yaml.MarshalWithSeparator(sl)
if err != nil {
return fmt.Errorf("marshaling new configs: %w", err)
}
if err := WriteFileFunc(filename, newCfgs); err != nil {
return fmt.Errorf("writing config file: %w", err)
}
return nil
}View on GitHub (pinned to a1189de023)
Solutions
- Run a YAML linter (yamllint or `yq . skaffold.yaml`) on the file and fix the reported syntax error.
- Check the wrapped %w detail for the exact line/column and correct indentation (spaces, no tabs).
- Restore the file from git if recent edits broke it: `git checkout -- skaffold.yaml`.
Example fix
// before (broken skaffold.yaml) metadata: name: app # tab indent // after metadata: name: app
Defensive patterns
Strategy: validation
Validate before calling
var node yaml.Node
if err := yaml.Unmarshal(data, &node); err != nil {
return fmt.Errorf("skaffold.yaml invalid: %w", err)
} Try / catch
if err := inspectCommand(); err != nil {
var pe *yaml.TypeError
if errors.As(err, &pe) || strings.Contains(err.Error(), "unable to parse YAML") {
// surface file/line from wrapped error
}
} Prevention
- Lint skaffold.yaml with yamllint/yq before running inspect commands
- Use spaces, never tabs, in YAML
- Validate after hand edits or merges with `skaffold inspect` dry reads
When it happens
Trigger: Calling skaffold inspect commands (e.g. `skaffold inspect modify-port-forward-resources`) against a skaffold.yaml (or file passed via --filename) that contains syntactically invalid YAML documents.
Common situations: Hand-edited skaffold.yaml with broken indentation, tabs mixed with spaces, stray characters, or truncated files after a failed merge/commit.
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
- parsing manifests file into manifest list object: %w
- marshaling new configs: %w
- yaml to json error: %w
- reading Kubernetes YAML: %w
- reading Kubernetes YAML: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/1438ed5157c5fc23.
Report an issue: GitHub.