{"record":{"id":"ddae4bf0ea04443e","repo":"golangci/golangci-lint","slug":"the-configuration-contains-invalid-elements-ddae4b","errorCode":null,"errorMessage":"the configuration contains invalid elements","messagePattern":"the configuration contains invalid elements","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/migrate.go","lineNumber":166,"sourceCode":"\n\tusedConfigFile := c.viper.ConfigFileUsed()\n\tif usedConfigFile == \"\" {\n\t\tc.log.Warnf(\"No config file detected\")\n\t\tos.Exit(exitcodes.NoConfigFileDetected)\n\t}\n\n\tc.log.Infof(\"Validating v1 configuration file: %s\", usedConfigFile)\n\n\terr := validateConfiguration(jsonsch.V1Schema, usedConfigFile)\n\tif err != nil {\n\t\tvar v *jsonschema.ValidationError\n\t\tif !errors.As(err, &v) {\n\t\t\treturn fmt.Errorf(\"[%s] validate: %w\", usedConfigFile, err)\n\t\t}\n\n\t\tprintValidationDetail(cmd, v.DetailedOutput())\n\n\t\treturn errors.New(\"the configuration contains invalid elements\")\n\t}\n\n\treturn nil\n}\n\nfunc (c *migrateCommand) persistentPreRunE(_ *cobra.Command, args []string) error {\n\tc.log.Infof(\"%s\", c.buildInfo.String())\n\n\tloader := config.NewBaseLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, c.opts.LoaderOptions, fakeloader.NewConfig(), args)\n\n\t// Loads the configuration just to get the effective path of the configuration.\n\terr := loader.Load()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"can't load config: %w\", err)\n\t}\n\n\tsrcPath := c.viper.ConfigFileUsed()\n\tif srcPath == \"\" {","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/migrate.go#L148-L184","documentation":"The migrate command's `preRunE` (pkg/commands/migrate.go:166) validates the existing golangci-lint configuration before migrating it from the v1 to the v2 format. If the JSON Schema validation of the current config fails, the detailed `jsonschema:` violations are printed and this generic message is returned. The migration refuses to proceed on a config that is not valid for the schema version it targets, since migrating an invalid config could silently produce a broken v2 file.","triggerScenarios":"Running `golangci-lint migrate` in a project whose `.golangci.yml` (or equivalent) contains keys, types, or values rejected by the JSON Schema — the same class of failure as `config verify`, but surfaced during migration.","commonSituations":"Migrating a v1 config that contains unknown or deprecated keys, wrong option types, or typos; configs copied from other projects; config files edited by hand or by older tooling with now-invalid options.","solutions":["Read the `jsonschema: ...` detail lines printed above this error — each names the failing config path and reason","Fix each reported key/value in the configuration file before re-running migrate","Verify the fixed config first with `golangci-lint config verify`, then re-run `golangci-lint migrate`"],"exampleFix":"# before (.golangci.yml)\nlinters-settings:\n  gocritic:\n    enabled-checks: rangeValCopy\n# after\nlinters-settings:\n  gocritic:\n    enabled-checks:\n      - rangeValCopy","handlingStrategy":"validation","validationCode":"if !exec.Command(\"golangci-lint\", \"config\", \"verify\").Run(); true {\n\t// run config verify first; only migrate when it exits 0\n}\n// recommended shell guard:\n// golangci-lint config verify && golangci-lint migrate","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run `golangci-lint config verify` before `migrate`","Clean up unknown/deprecated v1 options before migrating","Keep the config under review (diff) before running migration tooling"],"tags":["golangci-lint","migrate","config","jsonschema","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}