golangci/golangci-lint · error
TOML decode file %s: %w
Error message
TOML decode file %s: %w
What it means
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.
Source
Thrown at pkg/commands/internal/migrate/parser/parser.go:36
Name() string
}
// Decode decodes a file into data.
// The choice of the decoder is based on the file extension.
func Decode(file File, data any) error {
ext := filepath.Ext(file.Name())
switch strings.ToLower(ext) {
case ".yaml", ".yml", ".json":
err := yaml.NewDecoder(file).Decode(data)
if err != nil && !errors.Is(err, io.EOF) {
return fmt.Errorf("YAML decode file %s: %w", file.Name(), err)
}
case ".toml":
err := toml.NewDecoder(file).Decode(&data)
if err != nil {
return fmt.Errorf("TOML decode file %s: %w", file.Name(), err)
}
default:
return fmt.Errorf("unsupported file type: %s", ext)
}
return nil
}
// Encode encodes data into a file.
// The choice of the encoder is based on the file extension.
func Encode(data any, dstFile File) error {
ext := filepath.Ext(dstFile.Name())
switch strings.ToLower(ext) {
case ".yml", ".yaml":
encoder := yaml.NewEncoder(dstFile)
encoder.SetIndent(2)View on GitHub (pinned to ed7a235d2d)
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.
Example fix
// before (.golangci.toml) [linters] enable = gocritic // after [linters] enable = ["gocritic"]
Defensive patterns
Strategy: validation
Validate before calling
content, err := os.ReadFile(cfgPath)
if err != nil { return err }
if !toml.Validate(content) { return errors.New("invalid TOML in " + cfgPath) } Try / catch
if err := parser.Decode(f, &data); err != nil {
if strings.Contains(err.Error(), "TOML decode") {
// surface line/column from wrapped toml error
}
return err
} Prevention
- 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.
When it happens
Trigger: Calling Decode on a .toml file containing invalid TOML: unterminated strings, missing [section] brackets, duplicate keys within a table, or invalid key/value syntax.
Common situations: Hand-edited .golangci.toml with typos, copy-pasted TOML missing quotes around string values, or a file corrupted by automated tooling.
Related errors
- YAML decode file %s: %w
- [%s] TOML decode: %w
- hash plugin directory: %w
- file %s not found: %w
- file %s open: %w
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/9f80ea7b31dbdd6b.
Report an issue: GitHub.