{"record":{"id":"b0efd97eab2251c1","repo":"kataras/iris","slug":"s-w-b0efd9","errorCode":null,"errorMessage":"%s: %w","messagePattern":"%s: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"view/html.go","lineNumber":284,"sourceCode":"\n\t\tif info == nil || info.IsDir() {\n\t\t\treturn nil\n\t\t}\n\n\t\tif s.extension != \"\" {\n\t\t\tif !strings.HasSuffix(path, s.extension) {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t}\n\n\t\tif s.rootDir == rootDirName {\n\t\t\tpath = strings.TrimPrefix(path, rootDirName)\n\t\t\tpath = strings.TrimPrefix(path, \"/\")\n\t\t}\n\n\t\tbuf, err := asset(s.fs, path)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"%s: %w\", path, err)\n\t\t}\n\n\t\treturn s.parseTemplate(path, buf, nil)\n\t})\n\n\tif s.onLoaded != nil {\n\t\ts.onLoaded()\n\t}\n\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif s.Templates == nil {\n\t\treturn fmt.Errorf(\"no templates found\")\n\t}\n\n\treturn nil","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/view/html.go#L266-L302","documentation":"During HTMLEngine.Load, each discovered template file is read from the embedded/OS filesystem via the asset function. If reading fails (file missing, unreadable, fs error), the engine wraps the underlying error with the template path using fmt.Errorf(\"%s: %w\", path, err) so the offending template file is identified.","triggerScenarios":"HTMLEngine.Load (also invoked lazily by ExecuteWriter) iterating registered asset paths where s.fs.ReadFile/asset fails — e.g. an embedded FS that does not contain the template directory, or a path that was trimmed incorrectly (rootDirName prefix mismatch).","commonSituations":"Embedding templates with go:embed but forgetting the directive or embedding the wrong directory; building to a directory without the templates; using a relative loader root that doesn't match the embedded folder name so trimmed paths no longer resolve.","solutions":["Inspect the wrapped inner error (%w) for the real fs failure and fix the path or missing file.","Verify the embedded FS includes the template directory: //go:embed templates and templates/* passed to the engine.","Ensure the root directory name used by the loader matches the top-level folder in the fs so path trimming yields valid keys.","Call Load() at startup and log the full error chain to catch it before serving requests."],"exampleFix":"// before\n//go:embed templates/*.html\nvar tmplFS embed.FS\nengine := html.New(tmplFS, \".html\")\n// after (ensure extension/root match what Loader registered)\n//go:embed templates\nvar tmplFS embed.FS\nengine := html.New(tmplFS, \".html\").Reload(true)","handlingStrategy":"validation","validationCode":"entries, err := fs.ReadDir(tmplFS, \"templates\")\nif err != nil || len(entries) == 0 {\n    log.Fatalf(\"embedded templates missing or empty: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := engine.Load(); err != nil {\n    log.Fatalf(\"html engine load failed: %v\", err) // error includes template path: root cause\n}","preventionTips":["Include the whole template directory in go:embed (//go:embed templates) not a narrow pattern.","Call Load() during application boot and fail fast on any error.","Keep the loader's root directory name consistent with the embedded top-level folder.","Add a CI check that builds the binary and verifies templates render once."],"tags":["template-loading","filesystem","embedded-fs","view-engine"],"backgroundTag":"asset-read-failed","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}