siyuan-note/siyuan · error

document path [ ] already exists

Error message

document path [%s] already exists

What it means

validateLocations checks that no document to be created by the doc-tree template already exists in the notebook. If box.Exist(node.path) reports an existing document at the target path, creation is aborted with this error to avoid overwriting or merging into existing content.

Solutions

  1. Choose a different target parent or rename so the computed paths are free
  2. Delete or rename the conflicting existing document before re-running the template
  3. Ensure the template's node paths are unique among themselves

Example fix

// before: same template re-run into same parent, path /parent/MyTemplate exists
createDocTree(box, "/parent", "MyTemplate", def) // error
// after: unique root name per run
createDocTree(box, "/parent", "MyTemplate 2026-09-18", def)
Defensive patterns

Strategy: validation

Validate before calling

for _, n := range nodes { if box.Exist(n.path) { return fmt.Errorf("path %s exists", n.path) } }

Try / catch

err := validateLocations(collector, box)
if err != nil && strings.Contains(err.Error(), "already exists") {
  // pick a new root name/parent or rename the existing doc
}

Prevention

When it happens

Trigger: Inserting a doc-tree template whose computed paths (root path + node paths) collide with documents that already exist in the box — e.g. re-running the same template insertion twice, or two nodes resolving to the same path.

Common situations: Running the same doc-tree template a second time into the same parent; duplicate sibling names within the template causing identical paths; the target parent document already containing a child with the template's root name.

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


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/e87cfb4231582729. Report an issue: GitHub.

Appendix: 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 9f775e8a12)