golangci/golangci-lint · error
can't load config: %w
Error message
can't load config: %w
What it means
The run command's `persistentPreRunE` loads the full configuration through a LintersLoader with deprecation checks and validation enabled. Any failure (syntax, unknown/invalid keys, bad values, unreadable file) is wrapped as `can't load config: %w`. It is the run-command counterpart of the migrate loader error.
Source
Thrown at pkg/commands/run.go:159
setupRunPersistentFlags(runCmd.PersistentFlags(), &c.opts)
c.cmd = runCmd
return c
}
func (c *runCommand) persistentPreRunE(cmd *cobra.Command, args []string) error {
if err := c.startTracing(); err != nil {
return err
}
c.log.Infof("%s", c.buildInfo.String())
loader := config.NewLintersLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)
err := loader.Load(config.LoadOptions{CheckDeprecation: true, Validation: true})
if err != nil {
return fmt.Errorf("can't load config: %w", err)
}
// https://go.dev/doc/go1.25#container-aware-gomaxprocs
if c.cfg.Run.Concurrency != 0 {
runtime.GOMAXPROCS(c.cfg.Run.Concurrency)
}
return nil
}
func (c *runCommand) persistentPostRunE(_ *cobra.Command, _ []string) error {
if err := c.stopTracing(); err != nil {
return err
}
os.Exit(c.exitCode)
return nilView on GitHub (pinned to ed7a235d2d)
Solutions
- Read the wrapped error after 'can't load config:' — it names the exact file, key, or value that failed.
- Run `golangci-lint config verify` to validate the config against the schema.
- If migrating from v1, run `golangci-lint migrate` instead of hand-editing.
- Fix YAML syntax (indentation, lists vs scalars) at the reported location.
- Confirm the --config path exists on the machine running the command (especially in CI).
Example fix
# before (v1 config with v2 binary) run: deadline: 5m # after run: timeout: 5m
Defensive patterns
Strategy: validation
Validate before calling
// pre-flight config check in CI if [ ! -f .golangci.yml ]; then echo "config missing"; exit 1; fi golangci-lint config verify || exit 1
Try / catch
if err := loader.Load(config.LoadOptions{CheckDeprecation: true, Validation: true}); err != nil {
return fmt.Errorf("can't load config: %w", err) // read the wrapped cause for file/key
} Prevention
- Match config version to the binary major version (v1 config with v2 binary fails).
- Run `golangci-lint migrate` when upgrading from v1 instead of hand-editing.
- Run `golangci-lint config verify` in CI before `run`.
- Double-check linter names and settings keys against the docs.
- Ensure the --config path exists on the executing machine.
When it happens
Trigger: Running `golangci-lint run` with a config that fails loading: YAML/JSON syntax errors, unknown linter names or settings keys, invalid values for typed fields, deprecated keys flagged during strict loading, or an unreadable config path.
Common situations: Upgrading golangci-lint to v2 where old v1 keys are invalid; typos in linter names under `enable:`; using a v1 config with the v2 binary; CI passing a --config file that doesn't exist on the runner.
Related errors
- can't load config: %w
- hash plugin directory: %w
- file %s not found: %w
- file %s open: %w
- YAML decoding: %w
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/cb684d1ce157adf6.
Report an issue: GitHub.