kubernetes/kops · error
parsing yaml: %w
Error message
parsing yaml: %w
What it means
parseManifestFile unmarshals manifest bytes with sigs.k8s.io/yaml into the manifest struct and wraps any Unmarshal error. It is the single parse step used both by GetHash on embedded data and by the generatefileassets tool output, so it fires whenever manifest YAML is malformed or its fields have unexpected types.
Source
Thrown at pkg/assets/assetdata/data.go:98
type file struct {
Name string `json:"name,omitempty"`
SHA256 string `json:"sha256,omitempty"`
}
type fileStore struct {
Base string `json:"base,omitempty"`
}
type manifest struct {
FileStores []fileStore `json:"filestores,omitempty"`
Files []file `json:"files,omitempty"`
}
func parseManifestFile(b []byte) (*manifest, error) {
m := &manifest{}
if err := yaml.Unmarshal(b, m); err != nil {
return nil, fmt.Errorf("parsing yaml: %w", err)
}
return m, nil
}
func (m *manifest) Matches(canonicalURL string) []*file {
var matches []*file
for _, fileStore := range m.FileStores {
if !strings.HasPrefix(canonicalURL, fileStore.Base) {
continue
}
relativePath := strings.TrimPrefix(canonicalURL, fileStore.Base)
for i := range m.Files {
f := &m.Files[i]
if f.Name == relativePath {
matches = append(matches, f)
}
}
}View on GitHub (pinned to 4c8573c808)
Solutions
- Fix the YAML syntax at the line indicated in the wrapped error (indentation, tabs, quoting)
- Correct field types to match the manifest struct: filestores[].base (string), files[].name and files[].sha256 (strings)
- Regenerate the manifest via generatefileassets instead of manual editing
- Lint with a YAML parser before committing: yaml.Unmarshal round-trip in a test
Example fix
// before (tabs and wrong type)
files:
- name: kubelet
sha256: 12345
// after
files:
- name: kubelet
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 Defensive patterns
Strategy: validation
Validate before calling
func validateManifestYAML(b []byte) error {
m := &manifest{}
if err := yaml.Unmarshal(b, m); err != nil {
return err
}
for _, f := range m.Files {
if f.Name == "" || len(f.SHA256) != 64 {
return fmt.Errorf("bad file entry %q", f.Name)
}
}
return nil
} Try / catch
m, err := parseManifestFile(b)
if err != nil {
var yErr *yaml.TypeError
if errors.As(err, &yErr) {
// field type mismatch: fix the yaml field types
}
return err
} Prevention
- Run YAML lint / unmarshal round-trip checks in CI for all manifests
- Never commit merge-conflict residue in YAML files
- Use spaces, not tabs, for YAML indentation
- Generate manifests with the tool rather than editing by hand
When it happens
Trigger: yaml.Unmarshal fails on the input bytes: invalid YAML syntax, wrong types for filestores/files/sha256 fields, or structurally invalid documents.
Common situations: Hand-edited manifests with indentation errors; merge conflict markers left in YAML; a generated file corrupted by a bad download; passing a JSON/SHA256SUMS text file where YAML was expected.
Related errors
- error parsing addons or manifest: %v
- failed to parse objects: %w
- failed to parse objects: %w
- error parsing addon %q: %v
- error parsing yaml: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/7a769db76e90fdf2.
Report an issue: GitHub.