{"record":{"id":"f0dc42d6a0d40caa","repo":"golangci/golangci-lint","slug":"generate-imports-w","errorCode":null,"errorMessage":"generate imports: %w","messagePattern":"generate imports: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/internal/imports.go","lineNumber":32,"sourceCode":"\nimport (\n{{range .Imports -}}\n\t_ \"{{.}}\"\n{{end -}}\n)\n`\n\nfunc (b Builder) updatePluginsFile() error {\n\timportsDest := filepath.Join(b.repo, \"cmd\", \"golangci-lint\", \"plugins.go\")\n\n\tinfo, err := os.Stat(importsDest)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"file %s not found: %w\", importsDest, err)\n\t}\n\n\tsource, err := generateImports(b.cfg)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"generate imports: %w\", err)\n\t}\n\n\tb.log.Infof(\"generated imports info %s:\\n%s\\n\", importsDest, source)\n\n\terr = os.WriteFile(filepath.Clean(importsDest), source, info.Mode())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"write file %s: %w\", importsDest, err)\n\t}\n\n\treturn nil\n}\n\nfunc generateImports(cfg *Configuration) ([]byte, error) {\n\timpTmpl, err := template.New(\"plugins.go\").Parse(importsTemplate)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"parse template: %w\", err)\n\t}\n","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/internal/imports.go#L14-L50","documentation":"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.","triggerScenarios":"Builder.updatePluginsFile → generateImports receives a Configuration whose Plugins data cannot be rendered, or template.Execute returns an error while producing the plugins.go source.","commonSituations":"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.","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"],"exampleFix":"# before (config)\nplugins:\n  - module: example.com/myplugin\n# after\nplugins:\n  - module: example.com/myplugin\n    import: example.com/myplugin/pkg/plugin","handlingStrategy":"try-catch","validationCode":"for _, p := range cfg.Plugins {\n\tif p.Import == \"\" {\n\t\treturn fmt.Errorf(\"plugin %q missing import path\", p.Module)\n\t}\n}","typeGuard":null,"tryCatchPattern":"err := builder.Build(ctx)\nif err != nil && strings.HasPrefix(err.Error(), \"generate imports:\") {\n\treturn fmt.Errorf(\"invalid plugin configuration: %w\", err)\n}","preventionTips":["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"],"tags":["go","template","build"],"backgroundTag":"template-execution-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}