golangci/golangci-lint · error

failed to set analyzer setting %q with value %q: %w

Error message

failed to set analyzer setting %q with value %q: %w

What it means

This error is produced by golangci-lint's goanalysis linter when a flag.Value.Set() call fails while applying a user-supplied settings value to an analyzer's flag. It means the analyzer accepts the setting key, but the value itself could not be parsed/assigned (wrong type or malformed value). The wrapped error (%w) carries the underlying parse failure from the flag package.

Source

Thrown at pkg/goanalysis/linter.go:155

	}
	return ret
}

func (*Linter) configureAnalyzer(a *analysis.Analyzer, cfg map[string]any) error {
	for k, v := range cfg {
		f := a.Flags.Lookup(k)
		if f == nil {
			validFlagNames := allFlagNames(&a.Flags)
			if len(validFlagNames) == 0 {
				return errors.New("analyzer doesn't have settings")
			}

			return fmt.Errorf("analyzer doesn't have setting %q, valid settings: %v",
				k, validFlagNames)
		}

		if err := f.Value.Set(valueToString(v)); err != nil {
			return fmt.Errorf("failed to set analyzer setting %q with value %q: %w", k, v, err)
		}
	}

	return nil
}

func (lnt *Linter) configure() error {
	analyzersMap := map[string]*analysis.Analyzer{}
	for _, a := range lnt.analyzers {
		analyzersMap[a.Name] = a
	}

	for analyzerName, analyzerSettings := range lnt.cfg {
		a := analyzersMap[analyzerName]
		if a == nil {
			return fmt.Errorf("settings key %q must be valid analyzer name, valid analyzers: %v",
				analyzerName, lnt.allAnalyzerNames())
		}

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Check the wrapped %w error to see which value failed to parse and fix the value's type/format in .golangci.yml
  2. Consult the analyzer's valid flag types (flagset) and supply a value the flag package can parse (true/false for bool, integers unquoted, etc.)
  3. Quote string values correctly in YAML so they are not misinterpreted
  4. If the setting changed type in a newer linter version, update the config to the new type

Example fix

# before (.golangci.yml)
settings:
  someanalyzer:
    max-issues: "ten"
# after
settings:
  someanalyzer:
    max-issues: 10
Defensive patterns

Strategy: validation

Validate before calling

for k, v := range analyzerSettings {
    if !validFlags[k] {
        return fmt.Errorf("unknown setting %q", k)
    }
    if err := validateValueParseable(k, v); err != nil {
        return fmt.Errorf("setting %q has unparseable value %v: %w", k, v, err)
    }
}

Try / catch

if err := linter.Run(...); err != nil {
    var cfgErr *fmt.wrapError // or errors.As on your config error type
    if strings.Contains(err.Error(), "failed to set analyzer setting") {
        log.Fatalf("bad setting value in config: %v", err)
    }
}

Prevention

When it happens

Trigger: Running golangci-lint with a settings.golangci config where an analyzer setting has a value that fails flag.Value.Set — e.g. a string passed to a boolean/int flag, an unparseable duration, or a JSON/YAML scalar of the wrong type for a list-typed flag.

Common situations: Typo'd value types in .golangci.yml (e.g. setting `flag: "yes"` for a bool flag that only accepts true/false), migrating config between linter versions where a setting changed type, or programmatic configuration passing raw strings instead of parsed values.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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