golangci/golangci-lint · error
parse template: %w
Error message
parse template: %w
What it means
generateImports parses the embedded importsTemplate with template.New("plugins.go").Parse. If the template text is syntactically invalid, it returns 'parse template: %w'. Since the template ships inside the binary, this usually means the source tree was edited or a template action is malformed.
Source
Thrown at pkg/commands/internal/imports.go:48
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)
}
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)
}View on GitHub (pinned to ed7a235d2d)
Solutions
- Restore the original importsTemplate from upstream golangci-lint for your version
- Fix the template syntax at pkg/commands/internal/imports.go (the parse error names line/column)
- Remove any merge-conflict markers inside the template literal
- Validate the template with a small Go snippet (template.New(...).Parse) before rebuilding
Example fix
// before
importsTemplate = `package main {{ .BadAction `
// after
importsTemplate = `package main
import (
{{ range .Imports }} _ "{{ . }}"
{{ end }})
` Defensive patterns
Strategy: validation
Validate before calling
if _, err := template.New("plugins.go").Parse(importsTemplate); err != nil {
return fmt.Errorf("importsTemplate is invalid: %w", err)
} Try / catch
_, err := generateImports(cfg)
if err != nil && strings.HasPrefix(err.Error(), "parse template:") {
return fmt.Errorf("built-in template corrupted; restore pkg/commands/internal/imports.go from upstream: %w", err)
} Prevention
- Do not hand-edit importsTemplate without re-testing Parse
- Resolve merge conflicts carefully in files containing template literals
- Pin the golangci-lint source version when patching
- Add a unit test that parses all embedded templates
When it happens
Trigger: template.Parse fails on importsTemplate — malformed Go template actions ({{...}}), stray braces, or a locally edited template string in pkg/commands/internal/imports.go.
Common situations: Hand-editing importsTemplate and breaking syntax; unresolved merge-conflict markers inside the template literal; backtick/quoting issues when patching; copy-paste introducing invalid actions.
Related errors
- generate imports: %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/69413e79ad1bf7e7.
Report an issue: GitHub.