{"record":{"id":"be5227b660cdda77","repo":"charmbracelet/crush","slug":"parse-template-w","errorCode":null,"errorMessage":"parse template: %w","messagePattern":"parse template: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/stats.go","lineNumber":715,"sourceCode":"\t\treturn int64(n.Float64)\n\t}\n\treturn 0\n}\n\nfunc generateHTML(stats *Stats, projectStats []ProjectStats, projName, username, path string) error {\n\tstatsJSON, err := json.Marshal(stats)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tprojectStatsJSON, err := json.Marshal(projectStats)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\ttmpl, err := template.New(\"stats\").Parse(statsTemplate)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"parse template: %w\", err)\n\t}\n\n\tdata := struct {\n\t\tStatsJSON        template.JS\n\t\tProjectStatsJSON template.JS\n\t\tCSS              template.CSS\n\t\tJS               template.JS\n\t\tHeader           template.HTML\n\t\tHeartbit         template.HTML\n\t\tFooter           template.HTML\n\t\tFavicon          template.URL\n\t\tGeneratedAt      string\n\t\tProjectName      string\n\t\tUsername         string\n\t}{\n\t\tStatsJSON:        template.JS(statsJSON),\n\t\tProjectStatsJSON: template.JS(projectStatsJSON),\n\t\tCSS:              template.CSS(statsCSS),","sourceCodeStart":697,"sourceCodeEnd":733,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/cmd/stats.go#L697-L733","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst statsTemplate = `{{ if .Stats }} {{ end` // unbalanced action\n// after\nconst statsTemplate = `{{ if .Stats }}{{ end }}`","handlingStrategy":"validation","validationCode":"// fails fast at startup/test time\nif _, err := template.New(\"stats\").Parse(statsTemplate); err != nil {\n    panic(\"statsTemplate is invalid: \" + err.Error())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["template","html-template","cli","developer-error"],"backgroundTag":"template-parse-error","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}