{"record":{"id":"cb684d1ce157adf6","repo":"golangci/golangci-lint","slug":"can-t-load-config-w-cb684d","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/run.go","lineNumber":159,"sourceCode":"\tsetupRunPersistentFlags(runCmd.PersistentFlags(), &c.opts)\n\n\tc.cmd = runCmd\n\n\treturn c\n}\n\nfunc (c *runCommand) persistentPreRunE(cmd *cobra.Command, args []string) error {\n\tif err := c.startTracing(); err != nil {\n\t\treturn err\n\t}\n\n\tc.log.Infof(\"%s\", c.buildInfo.String())\n\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{CheckDeprecation: true, Validation: true})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"can't load config: %w\", err)\n\t}\n\n\t// https://go.dev/doc/go1.25#container-aware-gomaxprocs\n\tif c.cfg.Run.Concurrency != 0 {\n\t\truntime.GOMAXPROCS(c.cfg.Run.Concurrency)\n\t}\n\n\treturn nil\n}\n\nfunc (c *runCommand) persistentPostRunE(_ *cobra.Command, _ []string) error {\n\tif err := c.stopTracing(); err != nil {\n\t\treturn err\n\t}\n\n\tos.Exit(c.exitCode)\n\n\treturn nil","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/run.go#L141-L177","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"# before (v1 config with v2 binary)\nrun:\n  deadline: 5m\n# after\nrun:\n  timeout: 5m","handlingStrategy":"validation","validationCode":"// pre-flight config check in CI\nif [ ! -f .golangci.yml ]; then echo \"config missing\"; exit 1; fi\ngolangci-lint config verify || exit 1","typeGuard":null,"tryCatchPattern":"if err := loader.Load(config.LoadOptions{CheckDeprecation: true, Validation: true}); err != nil {\n    return fmt.Errorf(\"can't load config: %w\", err) // read the wrapped cause for file/key\n}","preventionTips":["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."],"tags":["go","config","lint","config-loading"],"backgroundTag":"config-load-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}