{"record":{"id":"9f80ea7b31dbdd6b","repo":"golangci/golangci-lint","slug":"toml-decode-file-s-w","errorCode":null,"errorMessage":"TOML decode file %s: %w","messagePattern":"TOML decode file (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/internal/migrate/parser/parser.go","lineNumber":36,"sourceCode":"\tName() string\n}\n\n// Decode decodes a file into data.\n// The choice of the decoder is based on the file extension.\nfunc Decode(file File, data any) error {\n\text := filepath.Ext(file.Name())\n\n\tswitch strings.ToLower(ext) {\n\tcase \".yaml\", \".yml\", \".json\":\n\t\terr := yaml.NewDecoder(file).Decode(data)\n\t\tif err != nil && !errors.Is(err, io.EOF) {\n\t\t\treturn fmt.Errorf(\"YAML decode file %s: %w\", file.Name(), err)\n\t\t}\n\n\tcase \".toml\":\n\t\terr := toml.NewDecoder(file).Decode(&data)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"TOML decode file %s: %w\", file.Name(), err)\n\t\t}\n\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported file type: %s\", ext)\n\t}\n\n\treturn nil\n}\n\n// Encode encodes data into a file.\n// The choice of the encoder is based on the file extension.\nfunc Encode(data any, dstFile File) error {\n\text := filepath.Ext(dstFile.Name())\n\n\tswitch strings.ToLower(ext) {\n\tcase \".yml\", \".yaml\":\n\t\tencoder := yaml.NewEncoder(dstFile)\n\t\tencoder.SetIndent(2)","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/internal/migrate/parser/parser.go#L18-L54","documentation":"parser.Decode wraps errors from toml.NewDecoder(file).Decode(&data) when a .toml configuration file cannot be parsed. It means the TOML content is syntactically invalid, so the migration/decode step cannot read the configuration.","triggerScenarios":"Calling Decode on a .toml file containing invalid TOML: unterminated strings, missing [section] brackets, duplicate keys within a table, or invalid key/value syntax.","commonSituations":"Hand-edited .golangci.toml with typos, copy-pasted TOML missing quotes around string values, or a file corrupted by automated tooling.","solutions":["Fix the TOML syntax at the reported location (the wrapped error names line/column).","Validate with a TOML linter such as `tomll` or an online TOML parser.","Quote all string values and ensure table headers like [linters] are properly declared.","Convert the config to YAML/JSON if TOML editing keeps causing issues."],"exampleFix":"// before (.golangci.toml)\n[linters]\nenable = gocritic\n// after\n[linters]\nenable = [\"gocritic\"]","handlingStrategy":"validation","validationCode":"content, err := os.ReadFile(cfgPath)\nif err != nil { return err }\nif !toml.Validate(content) { return errors.New(\"invalid TOML in \" + cfgPath) }","typeGuard":null,"tryCatchPattern":"if err := parser.Decode(f, &data); err != nil {\n    if strings.Contains(err.Error(), \"TOML decode\") {\n        // surface line/column from wrapped toml error\n    }\n    return err\n}","preventionTips":["Validate TOML with tomll or a TOML parser before use.","Always quote string values in TOML.","Prefer YAML/JSON configs if TOML editing is error-prone.","Run config verification in CI."],"tags":["go","toml","config","syntax"],"backgroundTag":"toml-parse-error","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}