golangci/golangci-lint · error
execute template: %w
Error message
execute template: %w
What it means
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.
Source
Thrown at pkg/commands/internal/imports.go:60
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)
}
var imps []string
for _, plugin := range cfg.Plugins {
imps = append(imps, plugin.Import)
}
buf := &bytes.Buffer{}
err = impTmpl.Execute(buf, map[string]any{"Imports": imps})
if err != nil {
return nil, fmt.Errorf("execute template: %w", err)
}
source, err := format.Source(buf.Bytes())
if err != nil {
return nil, fmt.Errorf("format source: %w", err)
}
return source, nil
}
View on GitHub (pinned to ed7a235d2d)
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
Example fix
// before (template references a field the data map lacks)
{{range .Imports}}
_ "{{.Module}}"
{{end}}
// after
{{range .Imports}}
_ "{{.}}"
{{end}} Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check: render the template manually and inspect output
var buf bytes.Buffer
if err := tmpl.Execute(&buf, map[string]any{"Imports": imps}); err != nil {
return fmt.Errorf("execute template: %w", err)
}
if buf.Len() == 0 {
return errors.New("template rendered empty output")
} Try / catch
source, err := generateImports(cfg)
if err != nil {
if errors.Is(err, template.ExecError{}) || strings.Contains(err.Error(), "execute template") {
// log template/data mismatch details and fix the template
}
return fmt.Errorf("generate imports: %w", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/3cffcec491a780de.
Report an issue: GitHub.