{"record":{"id":"03b9a1ee9ac304f8","repo":"golangci/golangci-lint","slug":"invalid-version-of-the-configuration-q","errorCode":null,"errorMessage":"invalid version of the configuration: %q","messagePattern":"invalid version of the configuration: %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/fmt.go","lineNumber":95,"sourceCode":"\treturn c\n}\n\nfunc (c *fmtCommand) persistentPreRunE(cmd *cobra.Command, args []string) error {\n\tc.log.Infof(\"%s\", c.buildInfo.String())\n\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{CheckDeprecation: true, Validation: true})\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 *fmtCommand) preRunE(_ *cobra.Command, _ []string) error {\n\tif c.cfg.GetConfigDir() != \"\" && c.cfg.Version != \"2\" {\n\t\treturn fmt.Errorf(\"invalid version of the configuration: %q\", c.cfg.Version)\n\t}\n\n\tmetaFormatter, err := goformatters.NewMetaFormatter(c.log, &c.cfg.Formatters, &c.cfg.Run)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create meta-formatter: %w\", err)\n\t}\n\n\tmatcher := processors.NewGeneratedFileMatcher(c.cfg.Formatters.Exclusions.Generated)\n\n\topts, err := goformat.NewRunnerOptions(c.cfg, c.opts.diff, c.opts.diffColored, c.opts.stdin)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"build walk options: %w\", err)\n\t}\n\n\tc.runner = goformat.NewRunner(c.log, metaFormatter, matcher, opts)\n\n\treturn nil\n}","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/fmt.go#L77-L113","documentation":"The fmt command's preRunE requires the configuration schema version to be \"2\" whenever a config directory is set (c.cfg.GetConfigDir() != \"\"). The formatters feature only supports the v2 config schema; an older v1 (or otherwise invalid) version string makes fmt refuse to run.","triggerScenarios":"Running `golangci-lint fmt` with a config file lacking `version: \"2\"` (or containing another value) while a config dir is detected — i.e., using a v1 .golangci.yml with the new formatters command.","commonSituations":"Upgraded golangci-lint to a release with the v2 schema but kept an old v1 config file; copied a legacy config; hand-edited the version key.","solutions":["Add `version: \"2\"` to the top of your config file and migrate settings to the new schema.","Use `golangci-lint migrate` (if available) to convert a v1 config to v2.","If you must keep the v1 config, do not use the `fmt` command / pin an older golangci-lint version."],"exampleFix":"// before (.golangci.yml)\nlinters:\n  enable: [gofmt]\n// after\nversion: \"2\"\nformatters:\n  enable: [gofmt]","handlingStrategy":"validation","validationCode":"// before invoking fmt, check the config declares v2\ndata, _ := os.ReadFile(configPath)\nif !regexp.MustCompile(`(?m)^\\s*version:\\s*[\"']?2[\"']?\\s*$`).Match(data) {\n  return fmt.Errorf(\"%s must contain `version: \\\"2\\\"` for the fmt command\", configPath)\n}","typeGuard":null,"tryCatchPattern":"if err := fmtCmd.Run(); err != nil {\n  if strings.Contains(err.Error(), \"invalid version of the configuration\") {\n    log.Fatal(\"migrate config to schema v2 (add `version: \\\"2\\\"` and move formatter settings)\")\n  }\n  return err\n}","preventionTips":["Add `version: \"2\"` at the top of .golangci.yml when adopting the formatters command.","Run `golangci-lint migrate` after upgrading from v1 config.","Don't hand-edit the version key without migrating the rest of the schema."],"tags":["golangci-lint","config","schema-version"],"backgroundTag":"unsupported-config-schema-version","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}