charmbracelet/crush · error
parse template: %w
Error message
parse template: %w
What it means
generateHTML wraps an error from template.New("stats").Parse(statsTemplate). This error fires only when the embedded statsTemplate constant fails to parse as a Go html/template — i.e. malformed template syntax such as unbalanced {{ }} braces, bad pipeline syntax, or an invalid action.
Source
Thrown at internal/cmd/stats.go:715
return int64(n.Float64)
}
return 0
}
func generateHTML(stats *Stats, projectStats []ProjectStats, projName, username, path string) error {
statsJSON, err := json.Marshal(stats)
if err != nil {
return err
}
projectStatsJSON, err := json.Marshal(projectStats)
if err != nil {
return err
}
tmpl, err := template.New("stats").Parse(statsTemplate)
if err != nil {
return fmt.Errorf("parse template: %w", err)
}
data := struct {
StatsJSON template.JS
ProjectStatsJSON template.JS
CSS template.CSS
JS template.JS
Header template.HTML
Heartbit template.HTML
Footer template.HTML
Favicon template.URL
GeneratedAt string
ProjectName string
Username string
}{
StatsJSON: template.JS(statsJSON),
ProjectStatsJSON: template.JS(projectStatsJSON),
CSS: template.CSS(statsCSS),View on GitHub (pinned to 7944b8e522)
Solutions
- Read the wrapped parse error for the line/position inside statsTemplate.
- Fix the template syntax in internal/cmd/stats.go (balance {{ }}, valid pipelines, defined functions).
- Add a test that calls template.New("stats").Parse(statsTemplate) to catch this at build time.
Example fix
// before
const statsTemplate = `{{ if .Stats }} {{ end` // unbalanced action
// after
const statsTemplate = `{{ if .Stats }}{{ end }}` Defensive patterns
Strategy: validation
Validate before calling
// fails fast at startup/test time
if _, err := template.New("stats").Parse(statsTemplate); err != nil {
panic("statsTemplate is invalid: " + err.Error())
} Prevention
- Add a unit test that parses every embedded template at CI time.
- Balance every {{ }} action; lint templates before committing.
- Register any custom template funcs in template.New(...).Funcs(...) before Parse.
- Run `go test ./internal/cmd/...` after editing statsTemplate.
When it happens
Trigger: Calling generateHTML when the compile-time statsTemplate string contains invalid Go template syntax. Since the template is embedded in the binary, this is essentially a build/code defect, not a runtime config problem.
Common situations: A developer edited statsTemplate and introduced unbalanced delimiters ({{ without }}), used an unknown function, or a syntax error inside an action; usually caught in CI before release.
Related errors
- execute template: %w
- ${sessionList} Use more characters or the full hash
- error creating prompt: %s
- parsing template: %w
- cannot continue an agent tool session: %s
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/be5227b660cdda77.
Report an issue: GitHub.