golangci/golangci-lint · error
[%s] validate: %w
Error message
[%s] validate: %w
What it means
During migrate's `preRunE`, the v1 configuration file is validated against the v1 JSON schema. If validation fails with an error that is NOT a jsonschema.ValidationError (i.e. an unexpected/non-schema failure such as an unreadable file), it is wrapped as `[%s] validate: %w`. Schema validation failures with details are instead printed and replaced by a generic message.
Source
Thrown at pkg/commands/migrate.go:161
}
if c.opts.skipValidation {
return nil
}
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 {View on GitHub (pinned to ed7a235d2d)
Solutions
- Fix the underlying error shown after this wrapper (often a YAML/JSON parse error).
- Validate the config file syntax with a YAML/JSON linter before running migrate.
- Ensure the config file exists and is readable by the current user.
- Run `golangci-lint config verify` to get schema validation details.
Example fix
# before (.golangci.yml with tabs)
linters:
enable: [govet]
# after (spaces)
linters:
enable:
- govet Defensive patterns
Strategy: validation
Validate before calling
// syntax-check the config as YAML before validating against the schema
var v any
if err := yaml.Unmarshal(data, &v); err != nil {
return fmt.Errorf("invalid YAML: %w", err)
} Try / catch
err := validateConfiguration(jsonsch.V1Schema, file)
var ve *jsonschema.ValidationError
if err != nil && !errors.As(err, &ve) {
return fmt.Errorf("[%s] validate: %w", file, err) // non-schema failure: fix syntax/IO first
} Prevention
- Lint YAML/JSON config files in CI before running golangci-lint.
- Avoid tabs in YAML; use spaces consistently.
- Ensure the config file exists and is readable at the path passed to --config.
- Use `golangci-lint config verify` as a pre-flight check.
When it happens
Trigger: Running migrate when the config file cannot be read/parsed by the validator for a non-schema reason — e.g. malformed YAML/JSON that the schema loader itself chokes on, a missing file, or an I/O error opening the config.
Common situations: Config file with syntax errors (bad indentation, tabs); file deleted between load and validation; permission issues reading the config; unusual encoding (BOM, non-UTF8).
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- can't load config: %w
- YAML decoding: %w
- YAML decode file %s: %w
- unsupported file type: %s
- can't load config: %w
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/8918b9a7b4ae014a.
Report an issue: GitHub.