golangci/golangci-lint · error

failed to decode configuration: %w

Error message

failed to decode configuration: %w

What it means

golangci-lint's revive wrapper decodes a serialized TOML configuration buffer into a lint.Config struct inside getConfig. This error is returned when toml.NewDecoder(buf).Decode(conf) fails, meaning the configuration handed to revive is syntactically invalid TOML or does not match the expected config structure. The underlying decode error is wrapped with %w, so the root cause (line/column or field type mismatch) is preserved in the message.

Source

Thrown at pkg/golinters/revive/revive.go:194

func getConfig(cfg *config.ReviveSettings) (*lint.Config, error) {
	conf := defaultConfig()

	// Since the Go version is dynamic, this value must be neutralized in order to compare with a "zero value" of the configuration structure.
	zero := &config.ReviveSettings{Go: cfg.Go}

	if !reflect.DeepEqual(cfg, zero) {
		rawRoot := createConfigMap(cfg)
		buf := bytes.NewBuffer(nil)

		err := toml.NewEncoder(buf).Encode(rawRoot)
		if err != nil {
			return nil, fmt.Errorf("failed to encode configuration: %w", err)
		}

		conf = &lint.Config{}
		_, err = toml.NewDecoder(buf).Decode(conf)
		if err != nil {
			return nil, fmt.Errorf("failed to decode configuration: %w", err)
		}
	}

	normalizeConfig(conf)

	for k, r := range conf.Rules {
		err := r.Initialize()
		if err != nil {
			return nil, fmt.Errorf("error in config of rule %q: %w", k, err)
		}
		conf.Rules[k] = r
	}

	return conf, nil
}

func createConfigMap(cfg *config.ReviveSettings) map[string]any {
	const severity = "severity"

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Inspect the wrapped cause after 'failed to decode configuration:' for the exact TOML line/column or type mismatch.
  2. Fix keys and value types in the revive settings block so they match revive's expected config (rules as a list/map, arguments as lists).
  3. Quote all TOML string values and fix indentation/tabs; validate the TOML with a linter such as taplo.
  4. Temporarily remove the revive settings block to confirm it is the source, then re-add entries incrementally.
  5. If it occurs with a stock config after an upgrade, pin the previous golangci-lint version and check for a regression.

Example fix

// before (.golangci.yml revive section, invalid TOML value)
linters-settings:
  revive:
    rules:
      var-naming: package-should-not-be-underlined
// after
linters-settings:
  revive:
    rules:
      - name: var-naming
        arguments: ["package-should-not-be-underlined"]
Defensive patterns

Strategy: validation

Validate before calling

// Validate revive TOML config before running the linter
import "github.com/BurntSushi/toml"

func validateReviveConfig(raw string) error {
	var cfg map[string]any
	if _, err := toml.Decode(raw, &cfg); err != nil {
		return fmt.Errorf("invalid revive TOML config: %w", err)
	}
	return nil
}

Try / catch

conf, err := getConfig(...)
if err != nil {
	var parseErr toml.ParseError
	if errors.As(err, &parseErr) {
		log.Fatalf("revive config TOML invalid: %v", err)
	}
	return fmt.Errorf("revive config error: %w", err)
}

Prevention

When it happens

Trigger: Calling newWrapper for the revive linter when the config buffer passed to toml.NewDecoder(buf).Decode(conf) cannot be parsed: malformed TOML syntax, unknown fields, or wrongly-typed values in the revive config section.

Common situations: Invalid TOML in the revive settings block of .golangci.yml (bad indentation, unquoted strings); assigning a scalar where revive expects a map or arguments list; an embedded config format change after upgrading golangci-lint.

Understand the failure class

Related errors


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