{"record":{"id":"2c2d12ea6bc8c11d","repo":"gofiber/fiber","slug":"failed-to-execute-w","errorCode":null,"errorMessage":"failed to execute: %w","messagePattern":"failed to execute: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"res.go","lineNumber":949,"sourceCode":"\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\nfunc (r *DefaultRes) renderExtensions(bind any) {\n\tr.c.renderExtensions(bind)\n}\n\n// Send sets the HTTP response body without copying it.","sourceCodeStart":931,"sourceCodeEnd":967,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/res.go#L931-L967","documentation":"Returned on the fallback branch of DefaultRes.Render() after a template parsed successfully but failed during tmpl.Execute(). Execution errors come from the data model, not the grammar: the template tried to evaluate an index, call a method, or range over a value that does not satisfy it.","triggerScenarios":"Calling ctx.Render(name, bind) with app.config.Views nil, where the parsed template references a field/method/type that bind does not provide: {{ .Address.City }} when bind has no Address; calling a method that returns two values where template expects one; ranging over a non-map/non-slice; a custom function that panics.","commonSituations":"Renaming a struct field without updating the template; passing fiber.Map with the wrong keys; passing a value of a different type than the template was written against; template calls a func that returns (T, error) — html/template disallows two-value methods unless the second is error.","solutions":["Read the wrapped error — html/template names the field/method and the template line.","Align the bind struct/map keys with the template's dotted access paths.","Ensure methods invoked from templates return either one value or (value, error).","For ranges, confirm the bind value is a slice, array, or map; for index access, confirm it is a map or a pointer to a struct with that field."],"exampleFix":"// before — template expects .Address.City but bind has no Address\ntype User struct{ Name string }\nreturn c.Render(\"user.gohtml\", User{Name: \"Ada\"})\n// user.gohtml: {{ .Address.City }}\n// -> failed to execute: template: ...: Address is not a field of struct ...\n\n// after\ntype User struct{ Name string; Address struct{ City string } }\nreturn c.Render(\"user.gohtml\", User{Name: \"Ada\", Address: struct{ City string }{\"London\"}})","handlingStrategy":"validation","validationCode":"// Execute templates against representative bind values in tests.\nfunc validateExecute(path string, bind any) error {\n    t, err := template.ParseFiles(path)\n    if err != nil { return err }\n    return t.Execute(io.Discard, bind)\n}","typeGuard":"// Ensure bind is a type the template was authored against.\nfunc isAcceptableBind(b any) bool {\n    switch b.(type) {\n    case fiber.Map, nil:\n        return true\n    }\n    v := reflect.ValueOf(b)\n    return v.Kind() == reflect.Struct || v.Kind() == reflect.Ptr && v.Elem().Kind() == reflect.Struct || v.Kind() == reflect.Map\n}","tryCatchPattern":"if err := c.Render(file, bind); err != nil {\n    if strings.Contains(err.Error(), \"failed to execute\") {\n        log.Printf(\"template execution mismatch for %s: %v\", file, err)\n        return fiber.ErrInternalServerError\n    }\n    return err\n}","preventionTips":["Keep bind types and templates in the same package/PR so they change together.","Avoid two-return methods in templates except (value, error).","Unit-test tmpl.Execute with the same bind shape the handler uses."],"tags":["rendering","template","go-template","execution","data-binding"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}