{"record":{"id":"7ae38a7944406308","repo":"golangci/golangci-lint","slug":"the-configuration-contains-invalid-elements","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/config_verify.go","lineNumber":39,"sourceCode":"func (c *configCommand) executeVerify(cmd *cobra.Command, _ []string) error {\n\tusedConfigFile := c.getUsedConfig()\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(\"Verifying the configuration file %q with the JSON Schema\", usedConfigFile)\n\n\terr := validateConfiguration(jsonsch.NextSchema, 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 validateConfiguration(schemaPath, targetFile string) error {\n\tcompiler := jsonschema.NewCompiler()\n\tcompiler.UseLoader(jsonsch.NewEmbedLoader())\n\tcompiler.DefaultDraft(jsonschema.Draft7)\n\n\t// The name is not us\n\tschema, err := compiler.Compile(schemaPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"compile schema: %w\", err)\n\t}\n\n\tvar m any\n","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/config_verify.go#L21-L57","documentation":"This error is returned by `config verify` (`executeVerify` in pkg/commands/config_verify.go:39) when the golangci-lint configuration file fails JSON Schema validation. The linter parses the config, validates it against the bundled JSON Schema for the current golangci-lint version, prints each schema violation via `printValidationDetail`, and then returns this generic sentinel message. It means the file exists and is parseable YAML/JSON/TOML, but its content contains keys, values, or structures the schema does not allow.","triggerScenarios":"Running `golangci-lint config verify` (or any command whose preRunE validates config) against a configuration file that decodes successfully but violates the golangci-lint JSON Schema: unknown top-level keys, wrong option types (e.g. `linters: enable` given a string instead of a list), invalid enum values, or options that do not exist in the schema version being used.","commonSituations":"Copying config snippets from blog posts or other projects with typos or deprecated keys; upgrading or downgrading golangci-lint so previously valid options disappear from the schema; mixing v1 and v2 configuration layouts; hand-editing YAML and mis-nesting keys.","solutions":["Run `golangci-lint config verify` and read each printed `jsonschema: ...` line above this error — it names the exact dotted path and keyword that failed","Fix the reported keys/values in the configuration file (remove unknown options, correct types/enums)","Regenerate or consult the schema for your version (`golangci-lint config` docs / jsonschema output) to confirm valid option names","If the config was migrated from v1, run the v2 migration and re-verify"],"exampleFix":"# before (.golangci.yml)\nlinters:\n  enable: gocritic\n  fast: true\n# after\nlinters:\n  enable:\n    - gocritic\nsettings:\n  gocritic:\n    enabled-checks:\n      - rangeValCopy","handlingStrategy":"validation","validationCode":"# shell — validate before other tooling consumes the config\nif ! golangci-lint config verify; then\n  echo \".golangci.yml is invalid; fix reported jsonschema errors first\" >&2\n  exit 1\nfi","typeGuard":null,"tryCatchPattern":"err := cmd.Run()\nvar vErr *exitcodes.ExitError\nif err != nil && strings.Contains(err.Error(), \"the configuration contains invalid elements\") {\n    // read the printed jsonschema detail lines and fix the config\n}\n_ = vErr","preventionTips":["Run `golangci-lint config verify` in CI before any step that consumes the config","Validate the config locally after every manual edit","Pin the golangci-lint version so config and schema stay in sync across machines","Regenerate configs from the official v2 template rather than copying v1 examples"],"tags":["golangci-lint","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"}