{"record":{"id":"adddf627c7f42912","repo":"golangci/golangci-lint","slug":"can-t-load-config-w-adddf6","errorCode":null,"errorMessage":"can't load config: %w","messagePattern":"can't load config: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/linters.go","lineNumber":76,"sourceCode":"\tfs := lintersCmd.Flags()\n\tfs.SortFlags = false // sort them as they are defined here\n\n\tsetupConfigFileFlagSet(fs, &c.opts.LoaderOptions)\n\tsetupLintersFlagSet(c.viper, fs)\n\n\tfs.BoolVar(&c.opts.JSON, \"json\", false, color.GreenString(\"Display as JSON\"))\n\n\tc.cmd = lintersCmd\n\n\treturn c\n}\n\nfunc (c *lintersCommand) preRunE(cmd *cobra.Command, args []string) error {\n\tloader := config.NewLintersLoader(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 *lintersCommand) execute(_ *cobra.Command, _ []string) error {\n\tenabledLintersMap, err := c.dbManager.GetEnabledLintersMap()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"can't get enabled linters: %w\", err)\n\t}","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/linters.go#L58-L94","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (.golangci.yml, deprecated key)\nlinters-settings:\n  golint:\n    min-confidence: 0.8\n// after\nlinters-settings:\n  revive:\n    min-confidence: 0.8","handlingStrategy":"validation","validationCode":"// run before invoking the linters command\n// golangci-lint config verify\n// or in Go:\nif _, err := os.Stat(cfgPath); err != nil {\n    return fmt.Errorf(\"config %s not readable: %w\", cfgPath, err)\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Execute(); err != nil {\n    if strings.Contains(err.Error(), \"can't load config\") {\n        // inspect wrapped cause; run `golangci-lint config path` and fix/verify\n    }\n    os.Exit(1)\n}","preventionTips":["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."],"tags":["go","config","validation","cli","golangci-lint"],"backgroundTag":"config-load-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}