{"record":{"id":"dc68c28721cb3932","repo":"golangci/golangci-lint","slug":"s-toml-decode-w","errorCode":null,"errorMessage":"[%s] TOML decode: %w","messagePattern":"\\[(.+?)\\] TOML decode: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/config_verify.go","lineNumber":121,"sourceCode":"\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}\n\n\treturn m, nil\n}\n","sourceCodeStart":103,"sourceCodeEnd":126,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/config_verify.go#L103-L126","documentation":"decodeTomlFile decodes the opened file with toml.NewDecoder(file).Decode(&m); if the document is not parseable TOML, the error is wrapped as \"[%s] TOML decode: %w\". This occurs while validating a .toml config during config verify.","triggerScenarios":"TOML decode fails: invalid TOML syntax (missing quotes around strings, wrong table header syntax, duplicate keys), or a value with the wrong type for its key.","commonSituations":"Mixing YAML-style syntax (indentation-based) into a TOML file; unquoted strings with special characters; using '=' vs ':' incorrectly; arrays with trailing commas of wrong element types; converting a YAML config to TOML by renaming only the extension.","solutions":["Read the wrapped %w error — the TOML parser reports line/column of the syntax problem; fix that line","Ensure strings are quoted and sections use [table] headers","Confirm key/value pairs use '=' and lists use TOML array syntax [\"a\", \"b\"]","Don't just rename .yml to .toml — convert the structure to TOML syntax","Validate locally with a TOML parser (e.g. toml-test or your editor's TOML plugin)"],"exampleFix":"# before (YAML-ish TOML)\nlinters:\n  enable:\n    - lll\n\n# after (valid TOML)\n[linters]\nenable = [\"lll\"]","handlingStrategy":"validation","validationCode":"func tomlPrecheck(path string) error {\n    data, err := os.ReadFile(path)\n    if err != nil {\n        return err\n    }\n    var v map[string]any\n    if _, err := toml.Decode(string(data), &v); err != nil {\n        return fmt.Errorf(\"invalid TOML (check reported line): %w\", err)\n    }\n    return nil\n}","typeGuard":"func isTOMLSyntaxError(err error) bool {\n    return err != nil && strings.Contains(strings.ToLower(err.Error()), \"toml\")\n}","tryCatchPattern":"if err := toml.NewDecoder(file).Decode(&m); err != nil {\n    return fmt.Errorf(\"fix TOML syntax at the reported line in %s: %w\", filename, err)\n}","preventionTips":["Use TOML syntax (tables, quoted strings, '=' assignments) — never paste YAML into .toml files","Run a TOML linter or editor plugin with schema support","Convert configs properly when migrating formats rather than renaming extensions","Test config changes in CI with `config verify`"],"tags":["toml","config","parsing"],"backgroundTag":"toml-parse-error","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}