golangci/golangci-lint · error
[%s] validate: %w
Error message
[%s] validate: %w
What it means
In executeVerify, the configuration file is validated against a JSON Schema via validateConfiguration. If the returned error is NOT a *jsonschema.ValidationError (i.e. an unexpected, infrastructure-level failure), it is wrapped as "[%s] validate: %w" with the config file path. Actual schema violations are instead printed as detail output and reported separately.
Source
Thrown at pkg/commands/config_verify.go:34
jsonsch "github.com/golangci/golangci-lint/v2/jsonschema"
"github.com/golangci/golangci-lint/v2/pkg/exitcodes"
)
func (c *configCommand) executeVerify(cmd *cobra.Command, _ []string) error {
usedConfigFile := c.getUsedConfig()
if usedConfigFile == "" {
c.log.Warnf("No config file detected")
os.Exit(exitcodes.NoConfigFileDetected)
}
c.log.Infof("Verifying the configuration file %q with the JSON Schema", usedConfigFile)
err := validateConfiguration(jsonsch.NextSchema, 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 validateConfiguration(schemaPath, targetFile string) error {
compiler := jsonschema.NewCompiler()
compiler.UseLoader(jsonsch.NewEmbedLoader())
compiler.DefaultDraft(jsonschema.Draft7)
// The name is not us
schema, err := compiler.Compile(schemaPath)
if err != nil {View on GitHub (pinned to ed7a235d2d)
Solutions
- Read the wrapped %w error — it usually points to a file-open/decode or schema-compile problem also wrapped in this package
- Verify the config file path passed to verify exists and has a supported extension (.yaml, .yml, .json, .toml)
- Reinstall the binary if the embedded schema appears missing/corrupt
- If the wrapped error IS a ValidationError, expect the separate message 'the configuration contains invalid elements' instead — fix the flagged config keys
Example fix
// before $ golangci-lint config verify ./nonexistent.yml // [./nonexistent.yml] validate: open ./nonexistent.yml: no such file or directory // after $ golangci-lint config verify .golangci.yml
Defensive patterns
Strategy: type-guard
Validate before calling
info, err := os.Stat(usedConfigFile)
if err != nil {
return fmt.Errorf("config file %s must exist before verify: %w", usedConfigFile, err)
}
switch strings.ToLower(filepath.Ext(usedConfigFile)) {
case ".yaml", ".yml", ".json", ".toml":
default:
return fmt.Errorf("unsupported config extension %s", filepath.Ext(usedConfigFile))
} Type guard
func isSchemaValidationError(err error) bool {
var v *jsonschema.ValidationError
return errors.As(err, &v)
} Try / catch
if err := validateConfiguration(jsonsch.NextSchema, usedConfigFile); err != nil {
var v *jsonschema.ValidationError
if !errors.As(err, &v) {
return fmt.Errorf("[%s] validate: %w", usedConfigFile, err) // infra failure, not user config
}
printValidationDetail(cmd, v.DetailedOutput())
return errors.New("the configuration contains invalid elements")
} Prevention
- Confirm the config file path and extension before running verify
- Distinguish ValidationError (fix your config) from other errors (tool/file problem)
- Reinstall the binary if verify fails with non-schema errors repeatedly
- Run verify in CI to catch config drift early
When it happens
Trigger: Running the config verify subcommand when validateConfiguration fails with a non-ValidationError — e.g. the embedded schema could not be compiled/applied, or the target file could not be read/decoded at all.
Common situations: Passing a file with an unsupported extension to verify; internal issue building the JSON Schema compiler; the schema asset is missing or corrupt in the installation.
Related errors
- the configuration contains invalid elements
- root field 'version' is required
- no plugins defined
- field 'module' is required
- missing information: 'version' or 'path' should be provided
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/c023c6a54e81f667.
Report an issue: GitHub.