{"record":{"id":"5d9ac728c53046f3","repo":"GoogleContainerTools/skaffold","slug":"parsing-api-version-w","errorCode":null,"errorMessage":"parsing api version: %w","messagePattern":"parsing api version: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/skaffold/schema/versions.go","lineNumber":272,"sourceCode":"// configFactoryFromAPIVersion checks that all configs in the input stream have the same API version, and returns a function to create a config with that API version.\nfunc configFactoryFromAPIVersion(buf []byte) ([]func() util.VersionedConfig, error) {\n\t// This is to quickly check that it's possibly a skaffold.yaml,\n\t// without parsing the whole file.\n\tif !bytes.Contains(buf, []byte(\"apiVersion\")) {\n\t\treturn nil, errors.New(\"missing apiVersion\")\n\t}\n\n\tvar factories []func() util.VersionedConfig\n\tb := bytes.NewReader(buf)\n\tdecoder := yaml.NewDecoder(b)\n\tfor {\n\t\tvar v APIVersion\n\t\terr := decoder.Decode(&v)\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(\"parsing api version: %w\", err)\n\t\t}\n\t\tfactory, present := AllVersions.Find(v.Version)\n\t\tif !present {\n\t\t\treturn nil, sErrors.ConfigUnknownAPIVersionErr(v.Version)\n\t\t}\n\t\tfactories = append(factories, factory)\n\t}\n\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)","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/schema/versions.go#L254-L290","documentation":"ParseConfig streams the YAML documents to discover each document's apiVersion. If the YAML decode of a document fails (not EOF), this wrapped error is returned. Note this is about decode failure — an unknown but successfully parsed version produces ConfigUnknownAPIVersionErr instead.","triggerScenarios":"Calling ParseConfig on a file containing malformed YAML (bad indentation, invalid syntax, wrong types) so the version-decoding pass errors before finding the apiVersion.","commonSituations":"Hand-edited skaffold.yaml with tab indentation or broken indentation; pasting YAML with smart quotes; truncated file from a failed write; multi-doc file with a corrupt segment.","solutions":["Run a YAML linter (yamllint) on skaffold.yaml to find syntax errors","Fix indentation — use spaces, never tabs","Check the wrapped cause (%w) for the exact line/parse problem","Restore the file from version control if it was truncated"],"exampleFix":"# before (tab indentation breaks YAML)\napiVersion: skaffold/v4beta7\nmetadata:\n\tname: app\n# after\napiVersion: skaffold/v4beta7\nmetadata:\n  name: app","handlingStrategy":"validation","validationCode":"var raw map[string]interface{}\nif err := yaml.Unmarshal(data, &raw); err != nil {\n\treturn fmt.Errorf(\"skaffold.yaml is not valid YAML: %w\", err)\n}\nif _, ok := raw[\"apiVersion\"]; !ok {\n\treturn errors.New(\"skaffold.yaml missing apiVersion\")\n}","typeGuard":null,"tryCatchPattern":"_, err := schema.ParseConfig(cfgPath)\nif err != nil {\n\tif strings.Contains(err.Error(), \"parsing api version\") {\n\t\t// surface a YAML-syntax hint to the user and stop\n\t}\n\treturn err\n}","preventionTips":["Lint YAML (yamllint) in CI before invoking skaffold","Use spaces, never tabs, for indentation","Pin the expected apiVersion and check it before parsing"],"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"}