{"record":{"id":"3e2d5aa8f2187a47","repo":"golangci/golangci-lint","slug":"can-t-load-config-w","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/config.go","lineNumber":97,"sourceCode":"\n\tpathFlagSet := pathCommand.Flags()\n\tpathFlagSet.BoolVar(&c.pathOpts.JSON, \"json\", false, color.GreenString(\"Display as JSON\"))\n\n\tc.cmd = configCmd\n\n\treturn c\n}\n\nfunc (c *configCommand) preRunE(cmd *cobra.Command, args []string) error {\n\t// The command doesn't depend on the real configuration.\n\t// It only needs to know the path of the configuration file.\n\tcfg := config.NewDefault()\n\n\tloader := config.NewLintersLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts, cfg, args)\n\n\terr := loader.Load(config.LoadOptions{})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"can't load config: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (c *configCommand) executePath(cmd *cobra.Command, _ []string) error {\n\tusedConfigFile := c.getUsedConfig()\n\n\tif c.pathOpts.JSON {\n\t\tabs, err := filepath.Abs(usedConfigFile)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\treturn json.NewEncoder(cmd.OutOrStdout()).Encode(map[string]string{\n\t\t\t\"path\":         usedConfigFile,\n\t\t\t\"absolutePath\": abs,\n\t\t})","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/config.go#L79-L115","documentation":"The config command's preRunE builds a default config and uses config.NewLintersLoader to load and process the user's configuration. Any failure from loader.Load(config.LoadOptions{}) — parsing, validation, or linters-settings resolution — is wrapped as \"can't load config: %w\".","triggerScenarios":"Invoking any config subcommand (e.g. `config path`) whose preRunE calls loader.Load, when the YAML/JSON config file is malformed or references unknown linters/settings.","commonSituations":"Typo in a config key or linter name; invalid YAML/JSON syntax (bad indentation, tabs); config file path wrong or unreadable; config written for an older/newer version with incompatible options.","solutions":["Inspect the wrapped %w error for the precise problem (line number in YAML, unknown key, unknown linter) and fix the config accordingly","Run the config verify subcommand (JSON Schema validation) to pinpoint invalid config elements","Confirm the config file path is correct and readable from the current working directory","If the config comes from an older release, migrate it to the current schema (check the changelog for renamed options)"],"exampleFix":"# before (.golangci.yml)\nlinters:\n  enable:\n    - lll\n  settings:\n    lll: { lin-length: 120 }   # unknown key\n\n# after\nlinters:\n  enable:\n    - lll\nsettings:\n  lll:\n    line-length: 120","handlingStrategy":"validation","validationCode":"func validateConfigBeforeLoad(path string) error {\n    data, err := os.ReadFile(path)\n    if err != nil {\n        return fmt.Errorf(\"config unreadable: %w\", err)\n    }\n    var v map[string]any\n    if err := yaml.Unmarshal(data, &v); err != nil {\n        return fmt.Errorf(\"config is not valid YAML: %w\", err)\n    }\n    return nil // then run `golangci-lint config verify` for schema-level checks\n}","typeGuard":"var loadErr *config.LoadError // or inspect wrapped causes\nif errors.As(err, &target) {\n    switch {\n    case errors.Is(err, os.ErrNotExist): // wrong path\n    case strings.Contains(err.Error(), \"unknown\"): // unknown linter/key\n    }\n}","tryCatchPattern":"if err := loader.Load(config.LoadOptions{}); err != nil {\n    if strings.Contains(err.Error(), \"unknown\") || strings.Contains(err.Error(), \"unmarshal\") {\n        log.Fatalf(\"config problem, run 'golangci-lint config verify' for details: %v\", err)\n    }\n    return fmt.Errorf(\"can't load config: %w\", err)\n}","preventionTips":["Run `config verify` (JSON Schema check) after every config edit or in CI","Start from the documented example config and change incrementally","Keep config file at a well-known path (.golangci.yml) to avoid path mistakes","After upgrading the tool, review the changelog for renamed/removed settings and update the config"],"tags":["config","yaml","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"}