{"record":{"id":"a465e8011f2fd601","repo":"golangci/golangci-lint","slug":"s-yaml-decode-w","errorCode":null,"errorMessage":"[%s] YAML decode: %w","messagePattern":"\\[(.+?)\\] YAML decode: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/config_verify.go","lineNumber":104,"sourceCode":"\t}\n\n\tfor _, d := range detail.Errors {\n\t\tprintValidationDetail(cmd, &d)\n\t}\n}\n\nfunc decodeYamlFile(filename string) (any, error) {\n\tfile, err := os.Open(filename)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] file open: %w\", filename, err)\n\t}\n\n\tdefer func() { _ = file.Close() }()\n\n\tvar m any\n\terr = yaml.NewDecoder(file).Decode(&m)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] YAML decode: %w\", filename, err)\n\t}\n\n\treturn m, nil\n}\n\nfunc decodeTomlFile(filename string) (any, error) {\n\tfile, err := os.Open(filename)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] file open: %w\", filename, err)\n\t}\n\n\tdefer func() { _ = file.Close() }()\n\n\tvar m any\n\terr = toml.NewDecoder(file).Decode(&m)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] TOML decode: %w\", filename, err)\n\t}","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/config_verify.go#L86-L122","documentation":"After successfully opening the file, decodeYamlFile decodes it with yaml.NewDecoder(file).Decode(&m). If the document is not parseable YAML, the error is wrapped as \"[%s] YAML decode: %w\". This happens while validating the config against the JSON Schema in config verify.","triggerScenarios":"yaml.Decode fails on a .yaml/.yml/.json config file: invalid YAML syntax, tabs for indentation, duplicate keys with strict mode, or non-mapping top-level document.","commonSituations":"Hand-edited YAML with tab indentation; missing space after a colon; unbalanced quotes/brackets; copy-pasted config with smart quotes; a .json file containing comments (JSON with // is invalid).","solutions":["Read the wrapped %w error — go-yaml reports the exact line/column of the syntax problem and fix that line","Replace tab characters with spaces for indentation","Ensure a space after each colon ('key: value') and balanced quotes","Remove comments from .json configs (YAML comments are not valid JSON) or rename the file to .yml","Paste the file into a YAML linter/parser locally to catch remaining syntax issues"],"exampleFix":"# before\nlinters:\n\tenable:\n\t  - lll\n\n# after (spaces, not tabs)\nlinters:\n  enable:\n    - lll","handlingStrategy":"validation","validationCode":"func yamlPrecheck(data []byte) error {\n    if bytes.ContainsRune(data, '\\t') {\n        if idx := bytes.IndexRune(data, '\\t'); idx >= 0 {\n            line := bytes.Count(data[:idx], []byte(\"\\n\")) + 1\n            return fmt.Errorf(\"tab character on line %d — use spaces\", line)\n        }\n    }\n    var v any\n    if err := yaml.Unmarshal(data, &v); err != nil {\n        return fmt.Errorf(\"invalid YAML: %w\", err)\n    }\n    return nil\n}","typeGuard":"func isYAMLSyntaxError(err error) bool {\n    var te *yaml.TypeError\n    return err != nil && !errors.As(err, &te) && strings.Contains(err.Error(), \"yaml:\")\n}","tryCatchPattern":"if err := yaml.NewDecoder(file).Decode(&m); err != nil {\n    return fmt.Errorf(\"fix the reported line/column in %s: %w\", filename, err)\n}","preventionTips":["Configure your editor to expand tabs to spaces in YAML files","Add a YAML lint step (yamllint) to CI before running the tool","Always put a space after colons and keep quotes balanced","Never put // comments in files saved as .json"],"tags":["yaml","config","parsing"],"backgroundTag":"yaml-parse-error","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}