golangci/golangci-lint · error
generate imports: %w
Error message
generate imports: %w
What it means
generateImports renders the plugins.go Go-template from the plugin configuration. If template execution (or building the imports list) fails, the error wraps the cause under 'generate imports:'. Build cannot proceed without a valid generated source.
Source
Thrown at pkg/commands/internal/imports.go:32
import (
{{range .Imports -}}
_ "{{.}}"
{{end -}}
)
`
func (b Builder) updatePluginsFile() error {
importsDest := filepath.Join(b.repo, "cmd", "golangci-lint", "plugins.go")
info, err := os.Stat(importsDest)
if err != nil {
return fmt.Errorf("file %s not found: %w", importsDest, err)
}
source, err := generateImports(b.cfg)
if err != nil {
return fmt.Errorf("generate imports: %w", err)
}
b.log.Infof("generated imports info %s:\n%s\n", importsDest, source)
err = os.WriteFile(filepath.Clean(importsDest), source, info.Mode())
if err != nil {
return fmt.Errorf("write file %s: %w", importsDest, err)
}
return nil
}
func generateImports(cfg *Configuration) ([]byte, error) {
impTmpl, err := template.New("plugins.go").Parse(importsTemplate)
if err != nil {
return nil, fmt.Errorf("parse template: %w", err)
}
View on GitHub (pinned to ed7a235d2d)
Solutions
- Fix the Plugins entries in the build configuration (valid, non-empty Import paths)
- Ensure the Configuration passed to Builder is fully populated and not nil
- Reconcile importsTemplate usage with the current golangci-lint version after an upgrade
- Re-run with verbose logging to see partially generated output and pinpoint the failing plugin
Example fix
# before (config)
plugins:
- module: example.com/myplugin
# after
plugins:
- module: example.com/myplugin
import: example.com/myplugin/pkg/plugin Defensive patterns
Strategy: try-catch
Validate before calling
for _, p := range cfg.Plugins {
if p.Import == "" {
return fmt.Errorf("plugin %q missing import path", p.Module)
}
} Try / catch
err := builder.Build(ctx)
if err != nil && strings.HasPrefix(err.Error(), "generate imports:") {
return fmt.Errorf("invalid plugin configuration: %w", err)
} Prevention
- Validate every plugin has a valid import path before calling Build
- Keep the build config in sync with the golangci-lint version's Configuration schema
- Unit-test generateImports with your config before real builds
- Avoid nil/partial Configuration values
When it happens
Trigger: Builder.updatePluginsFile → generateImports receives a Configuration whose Plugins data cannot be rendered, or template.Execute returns an error while producing the plugins.go source.
Common situations: Malformed plugin entries in the custom-build config (e.g. missing Import path); template data mismatch after upgrading golangci-lint source; nil/invalid cfg passed to Builder.
Related errors
- parse template: %w
- open source file: %w
- file %s not found: %w
- write file %s: %w
- failed to load packages: %w
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/f0dc42d6a0d40caa.
Report an issue: GitHub.