golangci/golangci-lint · error

failed to calculate config salt: %w

Error message

failed to calculate config salt: %w

What it means

initHashSalt computes a config salt by serializing the parts of the config that affect analysis (Linters.Settings and Run.BuildTags). If that serialization fails, the error is wrapped as "failed to calculate config salt". Note the same underlying error text can also surface as error 118.

Source

Thrown at pkg/commands/run.go:633

		return fmt.Sprintf("%db", memBytes)
	}
	if memBytes < Mb {
		return fmt.Sprintf("%dkb", memBytes/Kb)
	}
	return fmt.Sprintf("%dmb", memBytes/Mb)
}

// Related to cache.

func initHashSalt(logger logutils.Log, version string, cfg *config.Config) error {
	binSalt, err := computeBinarySalt(version)
	if err != nil {
		return fmt.Errorf("failed to calculate binary salt: %w", err)
	}

	configSalt, err := computeConfigSalt(cfg)
	if err != nil {
		return fmt.Errorf("failed to calculate config salt: %w", err)
	}

	goModSalt, err := computeGoModSalt()
	if err != nil {
		// NOTE: missing go.mod must be ignored.
		logger.Warnf("Failed to calculate go.mod salt: %v", err)
	}

	b := bytes.NewBuffer(binSalt)
	b.WriteString("golangci-lint-cache/v2")
	b.Write(configSalt)
	b.WriteString(goModSalt)

	cache.SetSalt(b)

	return nil
}

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Validate your .golangci.yml (check the config schema against your golangci-lint version) and simplify exotic settings.
  2. Run `golangci-lint config verify` to catch malformed configuration.
  3. Bisect settings: comment out linter-settings blocks until the error disappears to find the offending entry.
  4. Pin or upgrade golangci-lint to a version compatible with your config keys (deprecated keys may parse differently).
  5. Clear the cache (`golangci-lint cache clean`) after fixing the config.

Example fix

// before (.golangci.yml)
linters-settings:
  gocyclo:
    min-complexity: [not, a, number]
// after
linters-settings:
  gocyclo:
    min-complexity: 15
Defensive patterns

Strategy: validation

Validate before calling

// preflight: verify config before running
if err := exec.Command("golangci-lint", "config", "verify").Run(); err != nil {
	return fmt.Errorf("invalid .golangci.yml; config salt computation will fail: %w", err)
}

Try / catch

if err := cmd.Run(); err != nil && strings.Contains(err.Error(), "failed to calculate config salt") {
	log.Fatalf("check linter settings in .golangci.yml (unmarshalable/mistyped values): %v", err)
}

Prevention

When it happens

Trigger: computeConfigSalt returns an error, which per the implementation happens when yaml.Marshal of cfg.Linters.Settings fails — typically because the settings contain values that cannot be marshaled (unexpected types after programmatic config mutation).

Common situations: Custom builds or plugins that inject non-marshalable values into config.Linters.Settings; corrupted or programmatically-built config files; rarely, YAML library incompatibilities after upgrades.

Related errors


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