{"record":{"id":"f584cbd13fb2a3a8","repo":"golangci/golangci-lint","slug":"yaml-decoding-w","errorCode":null,"errorMessage":"YAML decoding: %w","messagePattern":"YAML decoding: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/internal/configuration.go","lineNumber":112,"sourceCode":"\nfunc LoadConfiguration() (*Configuration, error) {\n\tconfigFilePath, err := findConfigurationFile()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"file %s not found: %w\", configFilePath, err)\n\t}\n\n\tfile, err := os.Open(configFilePath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"file %s open: %w\", configFilePath, err)\n\t}\n\n\tdefer func() { _ = file.Close() }()\n\n\tvar cfg Configuration\n\n\terr = yaml.NewDecoder(file).Decode(&cfg)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"YAML decoding: %w\", err)\n\t}\n\n\treturn &cfg, nil\n}\n\nfunc findConfigurationFile() (string, error) {\n\tentries, err := os.ReadDir(\".\")\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"read directory: %w\", err)\n\t}\n\n\tfor _, entry := range entries {\n\t\text := filepath.Ext(entry.Name())\n\n\t\tswitch strings.ToLower(strings.TrimPrefix(ext, \".\")) {\n\t\tcase \"yml\", \"yaml\", \"json\":\n\t\t\tif isConf(ext, entry.Name()) {\n\t\t\t\treturn entry.Name(), nil","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/internal/configuration.go#L94-L130","documentation":"LoadConfiguration decodes the opened file with yaml.NewDecoder(file).Decode(&cfg) into a Configuration struct; this wrapper reports 'YAML decoding'. The file exists and opened fine but its content is not valid YAML, or is an empty stream / violates struct requirements during unmarshalling.","triggerScenarios":"yaml.Decode fails on malformed YAML (bad indentation, tabs, duplicate keys with strict settings), an empty config file (io.EOF from decoding an empty stream), or an incompatible scalar type for a Configuration field (e.g. string where an int is expected).","commonSituations":"Hand-edited config introducing tab indentation or missing space after a colon, config file left empty after a failed merge, pasted YAML with smart quotes, or schema drift after upgrading the tool to a version with new/changed field types.","solutions":["Validate the file with a YAML linter/parser (yamllint or python -c 'import yaml,sys; yaml.safe_load(open(sys.argv[1]))') to get the exact line","Fix indentation to spaces only — YAML forbids tabs; ensure 'key: value' has a space after the colon","If the file is intentionally empty, populate required fields (e.g. destination, plugins) — empty streams error on Decode into a struct","Compare fields against the Configuration struct of your installed version; remove/rename stale keys after upgrading","The wrapped error includes line/column — jump there and correct the syntax"],"exampleFix":"// before\nplugins:\n\t- path: ./x   # tab indentation\n// after\nplugins:\n  - path: ./x   # spaces only","handlingStrategy":"validation","validationCode":"data, err := os.ReadFile(configFilePath)\nif err != nil { return err }\nif len(strings.TrimSpace(string(data))) == 0 {\n    return fmt.Errorf(\"config %s is empty; populate required fields\", configFilePath)\n}\nvar probe map[string]any\nif err := yaml.Unmarshal(data, &probe); err != nil {\n    return fmt.Errorf(\"invalid YAML in %s: %w\", configFilePath, err)\n}","typeGuard":null,"tryCatchPattern":"cfg, err := LoadConfiguration()\nif err != nil {\n    var yerr *yaml.TypeError\n    switch {\n    case errors.As(err, &yerr):\n        log.Fatalf(\"config field type mismatch: %v — align fields with the Configuration schema for your version\", yerr)\n    case strings.Contains(err.Error(), \"YAML decoding\"):\n        log.Fatalf(\"config is not valid YAML: %v — run yamllint and fix the reported line\", err)\n    default:\n        return err\n    }\n}","preventionTips":["Run yamllint (or a CI YAML check) on config files before invoking the tool","Use spaces, never tabs, for YAML indentation","Never leave the config file empty; include all required keys","Re-validate the config schema after upgrading the tool to a new version"],"tags":["go","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"}