{"record":{"id":"3cffcec491a780de","repo":"golangci/golangci-lint","slug":"execute-template-w","errorCode":null,"errorMessage":"execute template: %w","messagePattern":"execute template: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/internal/imports.go","lineNumber":60,"sourceCode":"\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\n\tvar imps []string\n\tfor _, plugin := range cfg.Plugins {\n\t\timps = append(imps, plugin.Import)\n\t}\n\n\tbuf := &bytes.Buffer{}\n\n\terr = impTmpl.Execute(buf, map[string]any{\"Imports\": imps})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"execute template: %w\", err)\n\t}\n\n\tsource, err := format.Source(buf.Bytes())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"format source: %w\", err)\n\t}\n\n\treturn source, nil\n}\n","sourceCodeStart":42,"sourceCodeEnd":70,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/internal/imports.go#L42-L70","documentation":"generateImports renders the plugins.go template with the configured plugin import paths and then gofmts the result. The 'execute template: %w' wrap means template.Execute failed while writing the rendered output into the buffer. With the fixed importsTemplate this is nearly impossible at runtime (the template parses and the data map always supplies 'Imports'), so it usually indicates a modified/broken template or an unusable write target.","triggerScenarios":"Calling Builder.updatePluginsFile (or Test_generateImports) when the embedded template fails mid-execution — e.g. the template text was edited to reference a missing field/method on the map[string]any{'Imports': imps} data, or the underlying writer returns an error.","commonSituations":"Developers customizing importsTemplate in pkg/commands/internal/imports.go (typo in a {{.Field}} name, bad pipeline), or a nil/broken buffer writer; rarely hit with the stock template.","solutions":["Inspect the wrapped error from template.Execute; it names the template line and field that failed","Fix the template in pkg/commands/internal/imports.go so every referenced field exists on the map[string]any{'Imports': ...} data","Re-run updatePluginsFile (builder command) to verify the plugins.go generation succeeds","If a custom template was introduced, test it with Test_generateImports against sample Configuration data"],"exampleFix":"// before (template references a field the data map lacks)\n{{range .Imports}}\n\t_ \"{{.Module}}\"\n{{end}}\n// after\n{{range .Imports}}\n\t_ \"{{.}}\"\n{{end}}","handlingStrategy":"try-catch","validationCode":"// pre-check: render the template manually and inspect output\nvar buf bytes.Buffer\nif err := tmpl.Execute(&buf, map[string]any{\"Imports\": imps}); err != nil {\n    return fmt.Errorf(\"execute template: %w\", err)\n}\nif buf.Len() == 0 {\n    return errors.New(\"template rendered empty output\")\n}","typeGuard":null,"tryCatchPattern":"source, err := generateImports(cfg)\nif err != nil {\n    if errors.Is(err, template.ExecError{}) || strings.Contains(err.Error(), \"execute template\") {\n        // log template/data mismatch details and fix the template\n    }\n    return fmt.Errorf(\"generate imports: %w\", err)\n}","preventionTips":["Don't edit importsTemplate without running Test_generateImports","Keep template data fields and template references in sync","Validate plugin Import strings before rendering","Fail fast with the wrapped error rather than swallowing it"],"tags":["go","template-execution","code-generation"],"backgroundTag":"template-execution-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}