{"record":{"id":"3a745915f84e700d","repo":"GoogleContainerTools/skaffold","slug":"unable-to-parse-yaml-w-3a7459","errorCode":null,"errorMessage":"unable to parse YAML: %w","messagePattern":"unable to parse YAML: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/skaffold/schema/versions.go","lineNumber":298,"sourceCode":"\treturn factories, nil\n}\n\n// removeYamlAnchors removes all top-level keys starting with `.` from the input stream so they can be used as YAML anchors\nfunc removeYamlAnchors(buf []byte) ([]byte, error) {\n\tin := bytes.NewReader(buf)\n\tvar out bytes.Buffer\n\n\tdecoder := yaml.NewDecoder(in)\n\tdecoder.KnownFields(true)\n\tencoder := yaml.NewEncoder(&out)\n\tfor {\n\t\tparsed := make(map[string]interface{})\n\t\terr := decoder.Decode(parsed)\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"unable to parse YAML: %w\", err)\n\t\t}\n\t\tfor field := range parsed {\n\t\t\tif strings.HasPrefix(field, \".\") {\n\t\t\t\tdelete(parsed, field)\n\t\t\t}\n\t\t}\n\t\terr = encoder.Encode(parsed)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\terr := encoder.Close()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn out.Bytes(), nil\n}\n","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/schema/versions.go#L280-L316","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"# before (non-mapping document)\napiVersion: skaffold/v4beta7\nkind: Config\n---\njust a scalar\n# after\napiVersion: skaffold/v4beta7\nkind: Config","handlingStrategy":"validation","validationCode":"docs := strings.Split(string(data), \"\\n---\")\nfor _, d := range docs {\n\tvar m map[string]interface{}\n\tif err := yaml.Unmarshal([]byte(d), &m); err != nil || m == nil {\n\t\treturn fmt.Errorf(\"YAML document is not a valid mapping: %w\", err)\n\t}\n}","typeGuard":null,"tryCatchPattern":"_, err := schema.ParseConfig(cfgPath)\nif err != nil {\n\tif strings.Contains(err.Error(), \"unable to parse YAML\") {\n\t\t// run yamllint and show the wrapped cause to the user\n\t}\n\treturn err\n}","preventionTips":["Keep every document in skaffold.yaml a mapping","Avoid stray or trailing '---' separators","Run a YAML linter on every config change"],"tags":["skaffold","config-loading","yaml-parsing"],"backgroundTag":"yaml-parse-error","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}