{"record":{"id":"1438ed5157c5fc23","repo":"GoogleContainerTools/skaffold","slug":"unable-to-parse-yaml-w","errorCode":null,"errorMessage":"unable to parse YAML: %w","messagePattern":"unable to parse YAML: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/inspect/helper.go","lineNumber":71,"sourceCode":"}\n\nfunc marshalConfigSetForFile(filename string, cfgs parser.SkaffoldConfigSet) error {\n\tbuf, err := ReadFileFunc(filename)\n\tif err != nil {\n\t\treturn sErrors.ConfigParsingError(err)\n\t}\n\tin := bytes.NewReader(buf)\n\tdecoder := yamlv3.NewDecoder(in)\n\tdecoder.KnownFields(true)\n\tvar sl []interface{}\n\tfor {\n\t\tvar parsed yamlv3.Node\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 fmt.Errorf(\"unable to parse YAML: %w\", err)\n\t\t}\n\t\t// parsed content is a document so the `Content` slice has exactly one element\n\t\tsl = append(sl, parsed.Content[0])\n\t}\n\n\tfor i, cfg := range cfgs {\n\t\tsl[cfg.SourceIndex] = cfgs[i].SkaffoldConfig\n\t}\n\n\tnewCfgs, err := yaml.MarshalWithSeparator(sl)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"marshaling new configs: %w\", err)\n\t}\n\tif err := WriteFileFunc(filename, newCfgs); err != nil {\n\t\treturn fmt.Errorf(\"writing config file: %w\", err)\n\t}\n\treturn nil\n}","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/inspect/helper.go#L53-L89","documentation":"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.","triggerScenarios":"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.","commonSituations":"Hand-edited skaffold.yaml with broken indentation, tabs mixed with spaces, stray characters, or truncated files after a failed merge/commit.","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`."],"exampleFix":"// before (broken skaffold.yaml)\nmetadata:\n\tname: app   # tab indent\n// after\nmetadata:\n  name: app","handlingStrategy":"validation","validationCode":"var node yaml.Node\nif err := yaml.Unmarshal(data, &node); err != nil {\n    return fmt.Errorf(\"skaffold.yaml invalid: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := inspectCommand(); err != nil {\n    var pe *yaml.TypeError\n    if errors.As(err, &pe) || strings.Contains(err.Error(), \"unable to parse YAML\") {\n        // surface file/line from wrapped error\n    }\n}","preventionTips":["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"],"tags":["yaml","parsing","config-file"],"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"}