siyuan-note/siyuan · error
hidden template paths are reserved
Error message
hidden template paths are reserved
What it means
validateTemplateRelativePath rejects any path segment starting with a dot, reserving hidden files/directories inside the templates tree. This prevents templates from colliding with metadata, lock, or system files that the kernel stores in dot-prefixed entries.
Solutions
- Rename the file or directory so no segment starts with '.'
- Move templates out of dot-prefixed directories into normal ones
- Strip leading dots from user-supplied names before calling the API
Example fix
// before
DocSaveAsTemplateInDirectory(".hidden/tpl.md", ...)
// after
DocSaveAsTemplateInDirectory("hidden/tpl.md", ...) Defensive patterns
Strategy: validation
Validate before calling
func hasHiddenSegment(p string) bool {
for _, part := range strings.Split(p, "/") {
if strings.HasPrefix(part, ".") { return true }
}
return false
} Try / catch
if err := validateTemplateRelativePath(p, false); err != nil { /* prompt user to rename dot-prefixed entries */ } Prevention
- Avoid dot-prefixed names for template files and folders
- Keep tool metadata (.git etc.) out of the templates directory
When it happens
Trigger: Calling DocSaveAsTemplateInDirectory or checkTemplateFilePath with any segment beginning with '.', e.g. '.hidden/x.md', 'notes/.config.md', or a directory named '.tmp'.
Common situations: Users naming a template folder starting with a dot for 'invisibility', tools that create dot-directories (.git, .obsidian) inside the templates folder, or exporting from another app that prefixes temp names with '.'.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- invalid content template path
- invalid template path
- access to sensitive workspace file is forbidden
- archive entry escapes destination
- asset path is sensitive
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/b57032e36b49f06d.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_manage.go:65
}
type TemplateFileEntry struct {
Path string `json:"path"`
IsDir bool `json:"isDir"`
IsPackage bool `json:"isPackage,omitempty"`
}
// 访问已有模板只校验目录边界,不对文件名进行清理或改写。
func validateTemplateRelativePath(p string, allowRoot bool) error {
if p == "" && allowRoot {
return nil
}
if p == "" || !fs.ValidPath(p) || strings.ContainsAny(p, "\\:\x00") {
return errors.New("invalid template path")
}
for _, part := range strings.Split(p, "/") {
if strings.HasPrefix(part, ".") {
return errors.New("hidden template paths are reserved")
}
}
return nil
}
// 新名称保持跨平台可用,已有父目录沿用原名。
func validateNewTemplateName(p string) error {
part := path.Base(p)
device := strings.ToUpper(strings.SplitN(part, ".", 2)[0])
if device == "CON" || device == "PRN" || device == "AUX" || device == "NUL" || (len(device) == 4 && (strings.HasPrefix(device, "COM") || strings.HasPrefix(device, "LPT")) && device[3] >= '1' && device[3] <= '9') {
return errors.New("reserved template file name")
}
if strings.HasPrefix(part, ".") || strings.TrimSpace(part) != part || strings.HasSuffix(part, ".") || strings.ContainsAny(part, "\\:<>\"|?*") || strings.ContainsFunc(part, unicode.IsControl) {
return errors.New("invalid template path component")
}
return nil
}
View on GitHub (pinned to 9f775e8a12)