siyuan-note/siyuan · error
document path [%s] already exists
Error message
document path [%s] already exists
What it means
This error is thrown by validateLocations when rendering a template into a document tree plan: one of the generated node paths already exists in the notebook (box.Exist returns true). SiYuan refuses to overwrite an existing document, so the whole template application is aborted before any transaction runs. It is a pre-flight collision check on every flattened node path derived from the template.
Source
Thrown at kernel/model/template_doc_tree.go:297
for _, node := range nodes {
ret = append(ret, node)
ret = append(ret, flattenTemplateDocTreeNodes0(node.Children)...)
}
return
}
func (collector *templateDocTreeCollector) validateLocations() error {
box := Conf.Box(collector.boxID)
if nil == box {
return ErrBoxNotFound
}
allowCreateDeeper := nil != Conf.FileTree && Conf.FileTree.AllowCreateDeeper
for _, node := range flattenTemplateDocTreeNodes0(collector.nodes) {
if depth := strings.Count(node.path, "/"); 7 < depth && !allowCreateDeeper {
return errors.New(Conf.Language(118))
}
if box.Exist(node.path) {
return fmt.Errorf("document path [%s] already exists", node.path)
}
}
return nil
}
func (collector *templateDocTreeCollector) buildTree(node *TemplateDocTreeNode, renderedTree *parse.Tree) {
renderedRootID := renderedTree.Root.ID
renderedTree.Box = collector.boxID
renderedTree.Path = node.path
renderedTree.HPath = node.HPath
renderedTree.ID = node.ID
renderedTree.Root.ID = node.ID
renderedTree.Root.Spec = treenode.CurrentSpec
templateIALs := parse.IAL2Map(renderedTree.Root.KramdownIAL)
renderedTree.Root.KramdownIAL = [][]string{
{"id", node.ID},
{"title", html.EscapeAttrVal(node.Title)},
{"updated", util.TimeFromID(node.ID)},View on GitHub (pinned to 8641553a1f)
Solutions
- Rename or delete the existing document(s) whose path matches the template's generated path, then re-apply the template
- Change the template so child paths are unique (e.g. include the template's rendered name/date placeholder)
- Apply the template under a different parent document so the computed paths no longer collide
- If the collision is unexpected, verify which node path is reported in the message and inspect the notebook via the document tree for stale duplicates
Example fix
// before: template child path hard-coded, collides on second apply
childPath := parentPath + "/Notes"
// after: make the path unique per apply
cleanName := strings.ReplaceAll(time.Now().Format("2006-01-02 15:04:05"), ":", "-")
childPath := parentPath + "/Notes " + cleanName Defensive patterns
Strategy: validation
Validate before calling
// Go: check all template-generated paths before applying
for _, p := range plannedPaths {
if box.Exist(p) {
return fmt.Errorf("path %s already exists in notebook", p)
}
} Try / catch
// catch and surface which path collided so the user can rename or relocate
if err := validateLocations(...); err != nil {
log.Printf("template apply blocked: %v", err)
return userFacingRenameOrAbort()
} Prevention
- Include a unique placeholder (date/time or rendered doc name) in template child paths
- Check existing documents under the target parent before applying a template
- Avoid applying the same fixed-path template twice without renaming
- After sync, re-check for conflicts before re-running templates
When it happens
Trigger: Calling the template rendering flow (renderTemplateSource -> validateLocations) where a computed child document path (nested by depth, '/' separated) collides with an existing document path in the target notebook. Happens when applying the same template twice to the same parent, or when the template hard-codes child paths that already exist.
Common situations: Re-applying a document-tree template without renaming; two users creating documents from the same template concurrently; template content containing fixed child names like 'Inbox/Notes' that already exist in the workspace; syncing another device's created docs before re-running the template.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- createDocTree exceeds the maximum document count of %d
- invalid child template path
- template path is outside templates directory
- child template [%s] not found in the current template packag
- child template [%s] is not a regular file
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/e87cfb4231582729.
Report an issue: GitHub.