gin-gonic/gin · critical
the HTML debug render was created without files or glob patt
Error message
the HTML debug render was created without files or glob pattern or file system with patterns
What it means
HTMLDebug.loadTemplate (render/html.go:85) panics when the renderer was constructed with none of the supported template sources: no Files slice, no Glob pattern, and no FileSystem+Patterns pair. Without at least one source there is nothing to parse, so Gin aborts loudly rather than silently rendering empty output.
Source
Thrown at render/html.go:85
Data: data,
}
}
func (r HTMLDebug) loadTemplate() *template.Template {
if r.FuncMap == nil {
r.FuncMap = template.FuncMap{}
}
if len(r.Files) > 0 {
return template.Must(template.New("").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap).ParseFiles(r.Files...))
}
if r.Glob != "" {
return template.Must(template.New("").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap).ParseGlob(r.Glob))
}
if r.FileSystem != nil && len(r.Patterns) > 0 {
return template.Must(template.New("").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap).ParseFS(
fs.FileSystem{FileSystem: r.FileSystem}, r.Patterns...))
}
panic("the HTML debug render was created without files or glob pattern or file system with patterns")
}
// Render (HTML) executes template and writes its result with custom ContentType for response.
func (r HTML) Render(w http.ResponseWriter) error {
r.WriteContentType(w)
if r.Name == "" {
return r.Template.Execute(w, r.Data)
}
return r.Template.ExecuteTemplate(w, r.Name, r.Data)
}
// WriteContentType (HTML) writes HTML ContentType.
func (r HTML) WriteContentType(w http.ResponseWriter) {
writeContentType(w, htmlContentType)
}
View on GitHub (pinned to 34dac209ff)
Solutions
- Provide at least one source: Files []string, Glob string, or both FileSystem and Patterns.
- For production prefer gin.HTMLProduction{Template: template.Must(template.ParseFiles(...))} which parses once.
- Validate the config at startup with an explicit check before assigning to router.HTMLRender.
Example fix
// before
router.HTMLRender = &gin.HTMLDebug{}
// after
router.HTMLRender = &gin.HTMLDebug{
Files: []string{"templates/index.tmpl", "templates/layout.tmpl"},
} Defensive patterns
Strategy: validation
Validate before calling
func validateHTMLDebug(r *gin.HTMLDebug) error {
if len(r.Files) == 0 && r.Glob == "" && (r.FileSystem == nil || len(r.Patterns) == 0) {
return errors.New("HTMLDebug needs Files, Glob, or FileSystem+Patterns")
}
return nil
}
if err := validateHTMLDebug(&r); err != nil { log.Fatal(err) } Prevention
- Always set Files, Glob, or both FileSystem and Patterns on HTMLDebug.
- Prefer HTMLProduction in production — parse once, reuse.
- Add a smoke test that renders a sample template at startup.
When it happens
Trigger: Calling gin.New() then setting router.HTMLRender = &gin.HTMLDebug{} with all zero fields; passing only FileSystem without Patterns (or Patterns without FileSystem); misconfiguring after migrating from HTMLProduction.
Common situations: Refactor that moved template files but forgot to update the HTMLDebug config; conditional setup that leaves Files empty on a code path; expecting Glob to default to a directory.
Related errors
- gin mode unknown: ${value} (available mode: debug release te
- Cannot redirect with status code %d
- key %v does not exist
- http method ${httpMethod} is not valid
- URL parameters can not be used when serving a static file
AI-assisted analysis of gin-gonic/gin@34dac209ff (2026-08-04).
Data as JSON: /data/errors/303925c0475d84f1.json.
Report an issue: GitHub.