siyuan-note/siyuan · error
template path is not a regular file
Error message
template path is not a regular file
What it means
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.
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
Example fix
// before
ReadTemplateFile("data/templates") // directory
// after
ReadTemplateFile("data/templates/hello.md") // regular file Defensive patterns
Strategy: validation
Validate before calling
info, err := os.Stat(path)
if err != nil { return err }
if !info.Mode().IsRegular() { return fmt.Errorf("%s is not a regular file", path) } Type guard
func isRegularFile(path string) bool { i, err := os.Stat(path); return err == nil && i.Mode().IsRegular() } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- check data.zip failed
- child template [ ] is not a regular file
- Conf.Language(14) (copy data dir failed: )
- copy asset [ ] to [ ] failed
- create history directory
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/379a9c3ed94d041e.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_path.go:51
// ReadTemplateFile 在模板根目录内读取普通文件,禁止通过符号链接读取目录外的数据。
func ReadTemplateFile(p string) ([]byte, error) {
root, rel, err := openTemplatePath(p)
if err != nil {
return nil, err
}
defer root.Close()
file, err := root.Open(rel)
if err != nil {
return nil, err
}
defer file.Close()
info, err := file.Stat()
if err != nil {
return nil, err
}
if !info.Mode().IsRegular() {
return nil, errors.New("template path is not a regular file")
}
return io.ReadAll(file)
}
View on GitHub (pinned to 9f775e8a12)