{"record":{"id":"379a9c3ed94d041e","repo":"siyuan-note/siyuan","slug":"template-path-is-not-a-regular-file","errorCode":null,"errorMessage":"template path is not a regular file","messagePattern":"template path is not a regular file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_path.go","lineNumber":51,"sourceCode":"\n// ReadTemplateFile 在模板根目录内读取普通文件，禁止通过符号链接读取目录外的数据。\nfunc ReadTemplateFile(p string) ([]byte, error) {\n\troot, rel, err := openTemplatePath(p)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer root.Close()\n\tfile, err := root.Open(rel)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer file.Close()\n\tinfo, err := file.Stat()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif !info.Mode().IsRegular() {\n\t\treturn nil, errors.New(\"template path is not a regular file\")\n\t}\n\treturn io.ReadAll(file)\n}\n","sourceCodeStart":33,"sourceCodeEnd":55,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_path.go#L33-L55","documentation":"ReadTemplateFile opens a template file and refuses to read it unless the filesystem entry is a regular file. After opening the path and calling file.Stat(), it checks info.Mode().IsRegular(); directories, devices, sockets, FIFOs, and similar special files are rejected with this error to avoid reading unbounded or meaningless byte streams as template content.","triggerScenarios":"Calling ReadTemplateFile with a path that resolves to a directory, a named pipe/FIFO, a device node, or (on some platforms) a symlink target that is not a regular file. The open succeeds, so the failure surfaces only at the Stat/IsRegular check.","commonSituations":"A template directory path passed instead of a file path; a misconfigured template folder setting pointing at a directory; tmpfs/pipe-based paths in container setups; a symlink loop or symlink to /dev/null or a socket being used as a template.","solutions":["Pass the path of an actual template file, not a directory or special file","Verify with os.Stat(path).Mode().IsRegular() before calling","If a symlink is involved, ensure its target is a regular file","Recreate the template as a normal file if it was replaced by a pipe/device"],"exampleFix":"// before\nReadTemplateFile(\"data/templates\") // directory\n// after\nReadTemplateFile(\"data/templates/hello.md\") // regular file","handlingStrategy":"validation","validationCode":"info, err := os.Stat(path)\nif err != nil { return err }\nif !info.Mode().IsRegular() { return fmt.Errorf(\"%s is not a regular file\", path) }","typeGuard":"func isRegularFile(path string) bool { i, err := os.Stat(path); return err == nil && i.Mode().IsRegular() }","tryCatchPattern":null,"preventionTips":["Stat the path before calling ReadTemplateFile","Store template paths as full file paths, never directories","Avoid pointing templates at pipes, devices, or sockets","Test template configuration after changing template folder settings"],"tags":["filesystem","template","io"],"backgroundTag":"incompatible-source-type","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}