{"id":"303925c0475d84f1","repo":"gin-gonic/gin","slug":"the-html-debug-render-was-created-without-files-or","errorCode":null,"errorMessage":"the HTML debug render was created without files or glob pattern or file system with patterns","messagePattern":"the HTML debug render was created without files or glob pattern or file system with patterns","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"render/html.go","lineNumber":85,"sourceCode":"\t\tData:     data,\n\t}\n}\n\nfunc (r HTMLDebug) loadTemplate() *template.Template {\n\tif r.FuncMap == nil {\n\t\tr.FuncMap = template.FuncMap{}\n\t}\n\tif len(r.Files) > 0 {\n\t\treturn template.Must(template.New(\"\").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap).ParseFiles(r.Files...))\n\t}\n\tif r.Glob != \"\" {\n\t\treturn template.Must(template.New(\"\").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap).ParseGlob(r.Glob))\n\t}\n\tif r.FileSystem != nil && len(r.Patterns) > 0 {\n\t\treturn template.Must(template.New(\"\").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap).ParseFS(\n\t\t\tfs.FileSystem{FileSystem: r.FileSystem}, r.Patterns...))\n\t}\n\tpanic(\"the HTML debug render was created without files or glob pattern or file system with patterns\")\n}\n\n// Render (HTML) executes template and writes its result with custom ContentType for response.\nfunc (r HTML) Render(w http.ResponseWriter) error {\n\tr.WriteContentType(w)\n\n\tif r.Name == \"\" {\n\t\treturn r.Template.Execute(w, r.Data)\n\t}\n\treturn r.Template.ExecuteTemplate(w, r.Name, r.Data)\n}\n\n// WriteContentType (HTML) writes HTML ContentType.\nfunc (r HTML) WriteContentType(w http.ResponseWriter) {\n\twriteContentType(w, htmlContentType)\n}\n","sourceCodeStart":67,"sourceCodeEnd":102,"githubUrl":"https://github.com/gin-gonic/gin/blob/34dac209ffb6ef85cc78c5d217bbb7ad001d68fd/render/html.go#L67-L102","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nrouter.HTMLRender = &gin.HTMLDebug{}\n// after\nrouter.HTMLRender = &gin.HTMLDebug{\n    Files: []string{\"templates/index.tmpl\", \"templates/layout.tmpl\"},\n}","handlingStrategy":"validation","validationCode":"func validateHTMLDebug(r *gin.HTMLDebug) error {\n    if len(r.Files) == 0 && r.Glob == \"\" && (r.FileSystem == nil || len(r.Patterns) == 0) {\n        return errors.New(\"HTMLDebug needs Files, Glob, or FileSystem+Patterns\")\n    }\n    return nil\n}\nif err := validateHTMLDebug(&r); err != nil { log.Fatal(err) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["render","html","template","configuration","panic","go"],"analyzedSha":"34dac209ffb6ef85cc78c5d217bbb7ad001d68fd","analyzedAt":"2026-08-04T21:26:18.438Z","schemaVersion":2}