golangci/golangci-lint · error
can't load config: %w
Error message
can't load config: %w
What it means
The `linters` command's preRunE wraps any failure from loader.Load(config.LoadOptions{Validation: true}) — i.e. the golangci-lint configuration could not be loaded or failed validation. Everything downstream (building the linters DB) requires a valid config, so the command stops here with the wrapped cause preserved.
Source
Thrown at pkg/commands/linters.go:76
fs := lintersCmd.Flags()
fs.SortFlags = false // sort them as they are defined here
setupConfigFileFlagSet(fs, &c.opts.LoaderOptions)
setupLintersFlagSet(c.viper, fs)
fs.BoolVar(&c.opts.JSON, "json", false, color.GreenString("Display as JSON"))
c.cmd = lintersCmd
return c
}
func (c *lintersCommand) preRunE(cmd *cobra.Command, args []string) error {
loader := config.NewLintersLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)
err := loader.Load(config.LoadOptions{Validation: true})
if err != nil {
return fmt.Errorf("can't load config: %w", err)
}
dbManager, err := lintersdb.NewManager(c.log.Child(logutils.DebugKeyLintersDB), c.cfg,
lintersdb.NewLinterBuilder(), lintersdb.NewPluginModuleBuilder(c.log), lintersdb.NewPluginGoBuilder(c.log))
if err != nil {
return err
}
c.dbManager = dbManager
return nil
}
func (c *lintersCommand) execute(_ *cobra.Command, _ []string) error {
enabledLintersMap, err := c.dbManager.GetEnabledLintersMap()
if err != nil {
return fmt.Errorf("can't get enabled linters: %w", err)
}View on GitHub (pinned to ed7a235d2d)
Solutions
- Read the wrapped cause after 'can't load config:' — it names the exact file/line/key problem.
- Run `golangci-lint config verify` to validate the config against the JSON schema.
- Run `golangci-lint migrate` to convert configs from older versions to the current format.
- Fix or temporarily remove --config to test whether the file itself is the problem.
Example fix
// before (.golangci.yml, deprecated key)
linters-settings:
golint:
min-confidence: 0.8
// after
linters-settings:
revive:
min-confidence: 0.8 Defensive patterns
Strategy: validation
Validate before calling
// run before invoking the linters command
// golangci-lint config verify
// or in Go:
if _, err := os.Stat(cfgPath); err != nil {
return fmt.Errorf("config %s not readable: %w", cfgPath, err)
} Try / catch
if err := cmd.Execute(); err != nil {
if strings.Contains(err.Error(), "can't load config") {
// inspect wrapped cause; run `golangci-lint config path` and fix/verify
}
os.Exit(1)
} Prevention
- Add `golangci-lint config verify` to CI.
- Keep the config compatible with your pinned golangci-lint version; run migrate after upgrades.
- Enable JSON-schema validation in the editor.
- Verify --config paths exist in CI before running linters.
When it happens
Trigger: loader.Load fails while running `golangci-lint linters`: missing config file, invalid YAML/TOML/JSON, schema validation failures (unknown keys, bad types, deprecated settings), or unreadable file permissions.
Common situations: Upgrading golangci-lint to a version where config keys were renamed or removed, a malformed .golangci.yml, --config pointing to a nonexistent path, or running in a directory without the expected config.
Related errors
- the configuration contains invalid elements
- the configuration contains invalid elements
- can't set severity rule option: no default severity defined
- severity should be set
- enable-all and disable-all options must not be combined
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/adddf627c7f42912.
Report an issue: GitHub.