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

  1. Read the wrapped %w error — the TOML parser reports line/column of the syntax problem; fix that line
  2. Ensure strings are quoted and sections use [table] headers
  3. Confirm key/value pairs use '=' and lists use TOML array syntax ["a", "b"]
  4. Don't just rename .yml to .toml — convert the structure to TOML syntax
  5. 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

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


AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02). Data as JSON: /api/errors/dc68c28721cb3932. Report an issue: GitHub.