{"record":{"id":"59f6b435cf4e5a73","repo":"vitessio/vitess","slug":"failed-to-execute-logentry-template-v","errorCode":null,"errorMessage":"failed to execute logEntry template: %v","messagePattern":"failed to execute logEntry template: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"go/vt/throttler/throttlerlogz.go","lineNumber":167,"sourceCode":"\t\tif stateGreater(r.NewState, state) {\n\t\t\tstate = r.NewState\n\t\t}\n\t\tvar colorLevel string\n\t\tswitch state {\n\t\tcase stateIncreaseRate:\n\t\t\tcolorLevel = \"low\"\n\t\tcase stateDecreaseAndGuessRate:\n\t\t\tcolorLevel = \"medium\"\n\t\tcase stateEmergency:\n\t\t\tcolorLevel = \"high\"\n\t\t}\n\t\tdata := struct {\n\t\t\tResult\n\t\t\tColorLevel string\n\t\t}{r, colorLevel}\n\n\t\tif err := logEntryTemplate.Execute(w, data); err != nil {\n\t\t\tpanic(fmt.Sprintf(\"failed to execute logEntry template: %v\", err))\n\t\t}\n\t}\n\n\tlogz.EndHTMLTable(w)\n\n\t// Print footer.\n\tcount := len(results)\n\tvar d time.Duration\n\tif count > 0 {\n\t\td = results[0].Now.Sub(results[count-1].Now)\n\t}\n\tif err := logFooterTemplate.Execute(w, map[string]any{\n\t\t\"Count\":    count,\n\t\t\"TimeSpan\": fmt.Sprintf(\"%.1f\", d.Minutes()),\n\t}); err != nil {\n\t\tpanic(fmt.Sprintf(\"failed to execute logFooter template: %v\", err))\n\t}\n}","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/throttler/throttlerlogz.go#L149-L185","documentation":"showThrottlerLog renders each throttler log entry through logEntryTemplate; if template execution returns an error it panics. As with the header template, this should be impossible in normal operation and indicates the template and the Result/ColorLevel data struct are out of sync, or the response writer failed.","triggerScenarios":"Rendering /throttlerlogz when logEntryTemplate references fields missing from the anonymous struct{Result; ColorLevel string}, or the HTTP response write fails mid-stream (client disconnect).","commonSituations":"Forks/patches that changed Result fields without updating logEntryTemplate; client disconnection while streaming many entries.","solutions":["Align logEntryTemplate field references with the current Result struct","For streaming write failures, log and abort the response instead of panicking","Re-run throttlerlogz unit tests after any template or struct change"],"exampleFix":"// before\nif err := logEntryTemplate.Execute(w, data); err != nil {\n    panic(fmt.Sprintf(\"failed to execute logEntry template: %v\", err))\n}\n// after\nif err := logEntryTemplate.Execute(w, data); err != nil {\n    log.Warnf(\"failed to execute logEntry template: %v\", err)\n    return\n}","handlingStrategy":"try-catch","validationCode":"// verify template parses at startup\nif err := logEntryTemplate.Execute(io.Discard, struct{ Result; ColorLevel string }{}); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        log.Errorf(\"throttlerlogz entry render panic: %v\", r)\n        http.Error(w, \"internal error\", http.StatusInternalServerError)\n    }\n}()","preventionTips":["Keep logEntryTemplate in sync with Result struct changes","Test template rendering in unit tests","Treat client disconnects as non-fatal in HTML handlers"],"tags":["go","panic","http-handler","template","debug-page"],"backgroundTag":"template-execution-panic","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}