{"record":{"id":"c841b99e4d608050","repo":"golangci/golangci-lint","slug":"can-t-load-config-w-c841b9","errorCode":null,"errorMessage":"can't load config: %w","messagePattern":"can't load config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/formatters.go","lineNumber":77,"sourceCode":"\tfs.SortFlags = false // sort them as they are defined here\n\n\tsetupConfigFileFlagSet(fs, &c.opts.LoaderOptions)\n\n\tsetupFormattersFlagSet(c.viper, fs)\n\n\tfs.BoolVar(&c.opts.JSON, \"json\", false, color.GreenString(\"Display as JSON\"))\n\n\tc.cmd = formattersCmd\n\n\treturn c\n}\n\nfunc (c *formattersCommand) preRunE(cmd *cobra.Command, args []string) error {\n\tloader := config.NewFormattersLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)\n\n\terr := loader.Load(config.LoadOptions{Validation: true})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"can't load config: %w\", err)\n\t}\n\n\tdbManager, err := lintersdb.NewManager(c.log.Child(logutils.DebugKeyLintersDB), c.cfg,\n\t\tlintersdb.NewLinterBuilder(), lintersdb.NewPluginModuleBuilder(c.log), lintersdb.NewPluginGoBuilder(c.log))\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tc.dbManager = dbManager\n\n\treturn nil\n}\n\nfunc (c *formattersCommand) execute(_ *cobra.Command, _ []string) error {\n\tenabledLintersMap, err := c.dbManager.GetEnabledLintersMap()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"can't get enabled formatters: %w\", err)\n\t}","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/formatters.go#L59-L95","documentation":"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.","triggerScenarios":"Running `golangci-lint formatters` with a config file containing YAML errors, unknown/invalid keys, or values that fail validation.","commonSituations":"Malformed .golangci.yml; invalid entries in the formatters section; wrong --config path; deprecated/renamed keys after a version upgrade.","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)."],"exampleFix":"// before (.golangci.yml)\nformatters:\n  gofumpt:\n    extra-rules: \"yes\"  # wrong type\n// after\nformatters:\n  gofumpt:\n    extra-rules: true","handlingStrategy":"validation","validationCode":"out, err := exec.Command(\"golangci-lint\", \"config\", \"verify\").CombinedOutput()\nif err != nil {\n  return fmt.Errorf(\"config invalid, run before `formatters`: %s\", out)\n}","typeGuard":null,"tryCatchPattern":"if err := formattersCmd.Run(); err != nil {\n  if strings.Contains(err.Error(), \"can't load config\") {\n    log.Fatalf(\"fix config file: %v\", errors.Unwrap(err))\n  }\n  return err\n}","preventionTips":["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."],"tags":["golangci-lint","config","validation"],"backgroundTag":"config-load-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}