{"record":{"id":"294e05deff07ff19","repo":"gofiber/fiber","slug":"failed-to-parse-w","errorCode":null,"errorMessage":"failed to parse: %w","messagePattern":"failed to parse: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"res.go","lineNumber":944,"sourceCode":"\t\t\t\t\treturn err\n\t\t\t\t}\n\n\t\t\t\trendered = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tif !rendered {\n\t\t// Render raw template using 'name' as filepath if no engine is set\n\t\tvar tmpl *template.Template\n\t\tif _, err := readContent(buf, name); err != nil {\n\t\t\treturn err\n\t\t}\n\t\t// Parse template\n\t\ttmpl, err := template.New(\"\").Parse(rootApp.toString(buf.Bytes()))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to parse: %w\", err)\n\t\t}\n\t\tbuf.Reset()\n\t\t// Render template\n\t\tif err := tmpl.Execute(buf, bind); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to execute: %w\", err)\n\t\t}\n\t}\n\n\tresponse := &r.c.fasthttp.Response\n\n\t// Set Content-Type to text/html\n\tresponse.Header.SetContentType(MIMETextHTMLCharsetUTF8)\n\t// Set rendered template to body\n\tresponse.SetBody(buf.Bytes())\n\n\treturn nil\n}\n","sourceCodeStart":926,"sourceCodeEnd":962,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/res.go#L926-L962","documentation":"Returned on the fallback branch of DefaultRes.Render() when no Views engine is configured (app.config.Views == nil). Fiber reads the file at path 'name', parses its contents through the standard library html/template, and wraps a parse failure with 'failed to parse'. This is Go's own template grammar, not an external engine.","triggerScenarios":"Calling ctx.Render(name, bind) with app.config.Views unset, where 'name' points to a file whose contents violate Go text/template or html/template syntax: unclosed action {{, unmatched define, invalid pipeline, bad delimiter.","commonSituations":"Using Fiber without a template engine but shipping .gohtml files; migrating from a Handlebars/Pug engine to raw Go templates without rewriting syntax; editor saving with BOM or mixed encoding that breaks the {{ }} delimiters; a typo like {{ end}} without a matching {{ if }}.","solutions":["Open the file named in the call and run `go tool tmpl` or `gotemplate` against it to get the exact line/column of the syntax error.","Fix the template grammar: balance {{if}}/{{end}}, {{range}}/{{end}}, {{define}}/{{end}}, and close every action with }}.","If you intended to use a non-Go engine, set Config.Views to the appropriate gofiber/template engine instead of relying on the raw fallback.","Remove stray BOM/encoding artifacts from the file."],"exampleFix":"// before — broken Go template\n// user.gohtml: {{ .Name }} {{ end }}\nreturn c.Render(\"user.gohtml\", fiber.Map{\"Name\": \"Ada\"})\n// -> failed to parse: template: :1: unexpected {{end}}\n\n// after — balanced\n// user.gohtml: {{ .Name }}\nreturn c.Render(\"user.gohtml\", fiber.Map{\"Name\": \"Ada\"})","handlingStrategy":"validation","validationCode":"// Parse templates at build/test time to catch syntax errors early.\nimport \"html/template\"\nfunc validateTemplateFile(path string) error {\n    b, err := os.ReadFile(path)\n    if err != nil { return err }\n    _, err = template.New(path).Parse(string(b))\n    return err\n}","typeGuard":null,"tryCatchPattern":"if err := c.Render(file, bind); err != nil {\n    if strings.Contains(err.Error(), \"failed to parse\") {\n        log.Printf(\"template syntax error in %s: %v\", file, err)\n        return fiber.ErrInternalServerError\n    }\n    return err\n}","preventionTips":["Add a `go test` step that parses every .gohtml file in the repo.","Set Config.Views to a real engine if you do not intend raw Go templates.","Lint template files in CI with a template parser."],"tags":["rendering","template","go-template","parsing"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}