{"record":{"id":"7a769db76e90fdf2","repo":"kubernetes/kops","slug":"parsing-yaml-w","errorCode":null,"errorMessage":"parsing yaml: %w","messagePattern":"parsing yaml: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/assets/assetdata/data.go","lineNumber":98,"sourceCode":"\ntype file struct {\n\tName   string `json:\"name,omitempty\"`\n\tSHA256 string `json:\"sha256,omitempty\"`\n}\n\ntype fileStore struct {\n\tBase string `json:\"base,omitempty\"`\n}\n\ntype manifest struct {\n\tFileStores []fileStore `json:\"filestores,omitempty\"`\n\tFiles      []file      `json:\"files,omitempty\"`\n}\n\nfunc parseManifestFile(b []byte) (*manifest, error) {\n\tm := &manifest{}\n\tif err := yaml.Unmarshal(b, m); err != nil {\n\t\treturn nil, fmt.Errorf(\"parsing yaml: %w\", err)\n\t}\n\treturn m, nil\n}\n\nfunc (m *manifest) Matches(canonicalURL string) []*file {\n\tvar matches []*file\n\tfor _, fileStore := range m.FileStores {\n\t\tif !strings.HasPrefix(canonicalURL, fileStore.Base) {\n\t\t\tcontinue\n\t\t}\n\t\trelativePath := strings.TrimPrefix(canonicalURL, fileStore.Base)\n\t\tfor i := range m.Files {\n\t\t\tf := &m.Files[i]\n\t\t\tif f.Name == relativePath {\n\t\t\t\tmatches = append(matches, f)\n\t\t\t}\n\t\t}\n\t}","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/assets/assetdata/data.go#L80-L116","documentation":"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.","triggerScenarios":"yaml.Unmarshal fails on the input bytes: invalid YAML syntax, wrong types for filestores/files/sha256 fields, or structurally invalid documents.","commonSituations":"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.","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"],"exampleFix":"// before (tabs and wrong type)\nfiles:\n\t- name: kubelet\n\t  sha256: 12345\n// after\nfiles:\n  - name: kubelet\n    sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","handlingStrategy":"validation","validationCode":"func validateManifestYAML(b []byte) error {\n\tm := &manifest{}\n\tif err := yaml.Unmarshal(b, m); err != nil {\n\t\treturn err\n\t}\n\tfor _, f := range m.Files {\n\t\tif f.Name == \"\" || len(f.SHA256) != 64 {\n\t\t\treturn fmt.Errorf(\"bad file entry %q\", f.Name)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"m, err := parseManifestFile(b)\nif err != nil {\n\tvar yErr *yaml.TypeError\n\tif errors.As(err, &yErr) {\n\t\t// field type mismatch: fix the yaml field types\n\t}\n\treturn err\n}","preventionTips":["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"],"tags":["yaml","parsing","manifest"],"backgroundTag":"yaml-unmarshal-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}