golangci/golangci-lint · error

the configuration contains invalid elements

Error message

the configuration contains invalid elements

What it means

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.

Source

Thrown at pkg/commands/migrate.go:166

	usedConfigFile := c.viper.ConfigFileUsed()
	if usedConfigFile == "" {
		c.log.Warnf("No config file detected")
		os.Exit(exitcodes.NoConfigFileDetected)
	}

	c.log.Infof("Validating v1 configuration file: %s", usedConfigFile)

	err := validateConfiguration(jsonsch.V1Schema, usedConfigFile)
	if err != nil {
		var v *jsonschema.ValidationError
		if !errors.As(err, &v) {
			return fmt.Errorf("[%s] validate: %w", usedConfigFile, err)
		}

		printValidationDetail(cmd, v.DetailedOutput())

		return errors.New("the configuration contains invalid elements")
	}

	return nil
}

func (c *migrateCommand) persistentPreRunE(_ *cobra.Command, args []string) error {
	c.log.Infof("%s", c.buildInfo.String())

	loader := config.NewBaseLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, c.opts.LoaderOptions, fakeloader.NewConfig(), args)

	// Loads the configuration just to get the effective path of the configuration.
	err := loader.Load()
	if err != nil {
		return fmt.Errorf("can't load config: %w", err)
	}

	srcPath := c.viper.ConfigFileUsed()
	if srcPath == "" {

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Read the `jsonschema: ...` detail lines printed above this error — each names the failing config path and reason
  2. Fix each reported key/value in the configuration file before re-running migrate
  3. Verify the fixed config first with `golangci-lint config verify`, then re-run `golangci-lint migrate`

Example fix

# before (.golangci.yml)
linters-settings:
  gocritic:
    enabled-checks: rangeValCopy
# after
linters-settings:
  gocritic:
    enabled-checks:
      - rangeValCopy
Defensive patterns

Strategy: validation

Validate before calling

if !exec.Command("golangci-lint", "config", "verify").Run(); true {
	// run config verify first; only migrate when it exits 0
}
// recommended shell guard:
// golangci-lint config verify && golangci-lint migrate

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02). Data as JSON: /api/errors/ddae4bf0ea04443e. Report an issue: GitHub.