{"record":{"id":"8ba148d850763c62","repo":"gofiber/fiber","slug":"failed-to-open-w","errorCode":null,"errorMessage":"failed to open: %w","messagePattern":"failed to open: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helpers.go","lineNumber":158,"sourceCode":"\tvalue := reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())).Elem() //nolint:gosec // Access to unexported field is required for listeners that don't expose TLS config methods.\n\tif !value.IsValid() {\n\t\treturn nil\n\t}\n\n\tcfg, ok := value.Interface().(*tls.Config)\n\tif !ok {\n\t\treturn nil\n\t}\n\n\treturn cfg\n}\n\n// readContent opens a named file and read content from it\nfunc readContent(rf io.ReaderFrom, name string) (int64, error) {\n\t// Read file\n\tf, err := os.Open(filepath.Clean(name))\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to open: %w\", err)\n\t}\n\tdefer func() {\n\t\tif err = f.Close(); err != nil {\n\t\t\tlog.Errorf(\"Error closing file: %s\", err)\n\t\t}\n\t}()\n\tn, readErr := rf.ReadFrom(f)\n\tif readErr != nil {\n\t\treturn n, fmt.Errorf(\"failed to read: %w\", readErr)\n\t}\n\treturn n, nil\n}\n\n// quoteEscapeMask marks the lanes of w holding bytes quoteRawString must\n// escape: '\\\\', '\"', any C0 control (including HTAB), or DEL. Lanes >= 0x80\n// are never marked; non-ASCII bytes pass through verbatim. This is\n// utils.IndexNonQuotable's RFC 9110 set widened by HTAB, which the RFC\n// permits as qdtext but this function has always percent-encoded.","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/helpers.go#L140-L176","documentation":"Returned by the internal readContent helper when os.Open fails on the named file. readContent is used by Ctx.Render (res.go:938) to load a template file when no template engine is configured (raw html/template rendering). The error wraps the OS error: 'failed to open: open foo.tmpl: no such file or directory'.","triggerScenarios":"Calling c.Render(\"views/missing.tmpl\", bind) with no Views/engine set, or any code path routing through readContent where the file path does not resolve to a readable file.","commonSituations":"Wrong working directory (relative path resolved against the process cwd, not the source file), template path typo, file not deployed in the container image, restrictive file permissions, or rendering a path built from user input that does not exist.","solutions":["Use an absolute path or embed templates with go:embed so the path is stable regardless of cwd.","Confirm the binary's working directory at runtime (log os.Getwd) and resolve template roots from it.","Set Views with fiber's html engine so engine-relative template names are used instead of raw file paths.","Verify deploy artifacts include the template files (check the Docker image / CI output)."],"exampleFix":"// before\napp.Get(\"/\", func(c fiber.Ctx) error {\n    return c.Render(\"templates/home.tmpl\", fiber.Map{})\n})\n\n// after\n//go:embed templates/*\nvar tmplFS embed.FS\nengine := html.NewFileSystem(http.FS(tmplFS), \".tmpl\")\napp := fiber.New(fiber.Config{Views: engine})","handlingStrategy":"validation","validationCode":"// ensure the template path resolves before rendering\nabs, err := filepath.Abs(name)\nif err != nil {\n    return err\n}\nif _, err := os.Stat(abs); err != nil {\n    return fiber.NewError(fiber.StatusNotFound, \"template not found\")\n}","typeGuard":"null","tryCatchPattern":"if err := c.Render(name, bind); err != nil {\n    if strings.Contains(err.Error(), \"failed to open\") {\n        return fiber.NewError(fiber.StatusNotFound, \"template not found\")\n    }\n    return err\n}","preventionTips":["Embed templates with go:embed so paths are filesystem-independent.","Use fiber's html engine with Views set so engine-relative names are resolved consistently.","Log os.Getwd at startup to know what relative paths resolve against.","Confirm the deploy image includes the template files."],"tags":["template","filesystem","render","gofiber","configuration"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}