golangci/golangci-lint · error
[%s] TOML decode: %w
Error message
[%s] TOML decode: %w
What it means
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.
Source
Thrown at pkg/commands/config_verify.go:121
if err != nil {
return nil, fmt.Errorf("[%s] YAML decode: %w", filename, err)
}
return m, nil
}
func decodeTomlFile(filename string) (any, error) {
file, err := os.Open(filename)
if err != nil {
return nil, fmt.Errorf("[%s] file open: %w", filename, err)
}
defer func() { _ = file.Close() }()
var m any
err = toml.NewDecoder(file).Decode(&m)
if err != nil {
return nil, fmt.Errorf("[%s] TOML decode: %w", filename, err)
}
return m, nil
}
View on GitHub (pinned to ed7a235d2d)
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)
Example fix
# before (YAML-ish TOML)
linters:
enable:
- lll
# after (valid TOML)
[linters]
enable = ["lll"] Defensive patterns
Strategy: validation
Validate before calling
func tomlPrecheck(path string) error {
data, err := os.ReadFile(path)
if err != nil {
return err
}
var v map[string]any
if _, err := toml.Decode(string(data), &v); err != nil {
return fmt.Errorf("invalid TOML (check reported line): %w", err)
}
return nil
} Type guard
func isTOMLSyntaxError(err error) bool {
return err != nil && strings.Contains(strings.ToLower(err.Error()), "toml")
} Try / catch
if err := toml.NewDecoder(file).Decode(&m); err != nil {
return fmt.Errorf("fix TOML syntax at the reported line in %s: %w", filename, err)
} Prevention
- 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`
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- [%s] YAML decode: %w
- YAML decoding: %w
- TOML decode file %s: %w
- the configuration contains invalid elements
- unsupported configuration format
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/dc68c28721cb3932.
Report an issue: GitHub.