golangci/golangci-lint · error
can't load config: %w
Error message
can't load config: %w
What it means
The `formatters` command's preRunE loads configuration via config.NewFormattersLoader().Load() with validation enabled. Failure is wrapped as "can't load config". It means the config file/flags for the formatters command are unparseable or fail validation, so the command can't build its lintersdb manager.
Source
Thrown at pkg/commands/formatters.go:77
fs.SortFlags = false // sort them as they are defined here
setupConfigFileFlagSet(fs, &c.opts.LoaderOptions)
setupFormattersFlagSet(c.viper, fs)
fs.BoolVar(&c.opts.JSON, "json", false, color.GreenString("Display as JSON"))
c.cmd = formattersCmd
return c
}
func (c *formattersCommand) preRunE(cmd *cobra.Command, args []string) error {
loader := config.NewFormattersLoader(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 *formattersCommand) execute(_ *cobra.Command, _ []string) error {
enabledLintersMap, err := c.dbManager.GetEnabledLintersMap()
if err != nil {
return fmt.Errorf("can't get enabled formatters: %w", err)
}View on GitHub (pinned to ed7a235d2d)
Solutions
- Read the wrapped cause for the exact offending key or line and fix the config file.
- Run `golangci-lint config verify` to schema-check the config.
- Remove unknown or deprecated options.
- Confirm the intended config file is being loaded (check --config and current directory).
Example fix
// before (.golangci.yml)
formatters:
gofumpt:
extra-rules: "yes" # wrong type
// after
formatters:
gofumpt:
extra-rules: true Defensive patterns
Strategy: validation
Validate before calling
out, err := exec.Command("golangci-lint", "config", "verify").CombinedOutput()
if err != nil {
return fmt.Errorf("config invalid, run before `formatters`: %s", out)
} Try / catch
if err := formattersCmd.Run(); err != nil {
if strings.Contains(err.Error(), "can't load config") {
log.Fatalf("fix config file: %v", errors.Unwrap(err))
}
return err
} Prevention
- Run `golangci-lint config verify` in CI as a gate.
- Validate YAML syntax with a schema-aware editor before committing config changes.
- Review upgrade/changelog notes for renamed or removed config keys.
- Pass --config explicitly when multiple config files exist in the tree.
When it happens
Trigger: Running `golangci-lint formatters` with a config file containing YAML errors, unknown/invalid keys, or values that fail validation.
Common situations: Malformed .golangci.yml; invalid entries in the formatters section; wrong --config path; deprecated/renamed keys after a version upgrade.
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/c841b99e4d608050.
Report an issue: GitHub.